Example #1
0
 static function copyResizedImage($inputFile, $outputFile, $width, $height = null, $crop = true)
 {
     if (extension_loaded('gd')) {
         $image = new GD($inputFile);
         if ($height) {
             if ($width && $crop) {
                 $image->cropThumbnail($width, $height);
             } else {
                 $image->resize($width, $height);
             }
         } else {
             $image->resize($width);
         }
         return $image->save($outputFile);
     } elseif (extension_loaded('imagick')) {
         $image = new \Imagick($inputFile);
         if ($height && !$crop) {
             $image->resizeImage($width, $height, \Imagick::FILTER_LANCZOS, 1, true);
         } else {
             $image->resizeImage($width, null, \Imagick::FILTER_LANCZOS, 1);
         }
         if ($height && $crop) {
             $image->cropThumbnailImage($width, $height);
         }
         return $image->writeImage($outputFile);
     } else {
         throw new HttpException(500, 'Please install GD or Imagick extension');
     }
 }
Example #2
0
 public static function getImageSize($filepath)
 {
     if (extension_loaded('gd')) {
         $image = new GD($filepath);
         return $image->getSize();
     }
 }