BaseFrontendClass.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace app\models\base;
  3. use yii\db\ActiveRecord;
  4. class BaseFrontendClass extends ActiveRecord
  5. {
  6. public static function getDb()
  7. {
  8. return \Yii::$app->db;
  9. }
  10. public function generatePreview( $ifile, $ofile, $w, $h)
  11. {
  12. list($width, $height) = getimagesize($ifile);
  13. // echo "convert -define jpeg:size=".$w."x".$h."+".$x."+".$y." $ifile -crop ".$w."x".$h."+".$x."+".$y." -thumbnail ".$ww."x".$hh."^ -gravity center $ofile";
  14. umask(0113);
  15. exec("convert -define jpeg:size=".$width."x".$height."+0+0 $ifile -thumbnail ".$w."x".$h."^ -gravity center -background '#FFFFFF' -quality 95 $ofile" );
  16. chmod($ofile, 0664);
  17. }
  18. public function generateImageCrop( $ifile, $ofile, $ww, $hh, $param )
  19. {
  20. // to do add rotate, etc
  21. extract( $param );
  22. list($width, $height) = getimagesize($ifile);
  23. $addp = '';
  24. if( strrpos($ofile, '.webp') == strlen($ofile) - strlen('.webp') )
  25. {
  26. $addp = " -background '#FFFFFF' -alpha off -strip Plane -quality 88 -define webp:method=6 "; //-interlace
  27. }
  28. umask(0113);
  29. // echo "convert -define jpeg:size=".$w."x".$h."+".$x."+".$y." $ifile -crop ".$w."x".$h."+".$x."+".$y." -thumbnail ".$ww."x".$hh."^ -gravity center $ofile";
  30. exec("convert -define jpeg:size=".$width."x".$height."+0+0 $ifile -crop ".$w."x".$h."+".$x."+".$y." -thumbnail ".$ww."x".$hh."^ $addp -gravity center $ofile" ); //> /dev/null 2>&1 & > /dev/null & в фоне
  31. // chmod($ofile, 0664);
  32. }
  33. }