Example #1
0
 /**
  * Creates and returns a thumbnail image object from an image file
  *
  * @param string  $file   file to convert
  * @param boolean $inline thumbs or zoom
  *
  * @return null/$new_image
  */
 public static function createThumbnail($file, $inline = false)
 {
     if ($inline == true) {
         $max_width = 100;
         $max_height = 200;
     } else {
         if (is_int(SetUp::getConfig('thumbnails_width'))) {
             $max_width = SetUp::getConfig('thumbnails_width');
         } else {
             $max_width = 200;
         }
         if (is_int(SetUp::getConfig('thumbnails_height'))) {
             $max_height = SetUp::getConfig('thumbnails_height');
         } else {
             $max_height = 200;
         }
     }
     if (File::isPdfFile($file)) {
         $image = ImageServer::openPdf($file);
     } else {
         $image = ImageServer::openImage($file);
     }
     if ($image == false) {
         return;
     }
     imagealphablending($image, true);
     imagesavealpha($image, true);
     $width = imagesx($image);
     $height = imagesy($image);
     $new_width = $max_width;
     $new_height = $max_height;
     if ($width / $height > $new_width / $new_height) {
         $new_height = $new_width * ($height / $width);
     } else {
         $new_width = $new_height * ($width / $height);
     }
     if ($new_width >= $width && $new_height >= $height) {
         $new_width = $width;
         $new_height = $height;
     }
     $new_image = ImageCreateTrueColor($new_width, $new_height);
     imagealphablending($new_image, true);
     imagesavealpha($new_image, true);
     $trans_colour = imagecolorallocatealpha($new_image, 0, 0, 0, 127);
     imagefill($new_image, 0, 0, $trans_colour);
     imagecopyResampled($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
     return $new_image;
 }