Example #1
0
 /**
  * A smart thumbnailing function. Generates thumbnail images without
  * distorting the output of the final image.
  * 
  * @param string $file
  * @param string $width
  * @param string $height
  * @param string $head
  * @return string
  */
 public static function thumbnail($file, $width, $height, $head = false)
 {
     if (!is_file($file)) {
         return;
     }
     $uuid = md5($file);
     $src = SOFTWARE_HOME . "app/temp/{$uuid}.thumb.{$width}.{$height}.jpeg";
     if (!is_file($src) || filectime($file) > filectime($src)) {
         $im = imagecreatefromjpeg($file);
         $i_width = imagesx($im);
         $i_height = imagesy($im);
         imagedestroy($im);
         $tempImage = uniqid() . ".jpeg";
         if ($width > $height) {
             ImageCache::resize_image($file, SOFTWARE_HOME . "app/temp/{$tempImage}", $width, 0);
             ImageCache::crop_image(SOFTWARE_HOME . "app/temp/{$tempImage}", $src, $width, $height, $head);
         } else {
             if ($height > $width) {
                 ImageCache::resize_image($file, SOFTWARE_HOME . "app/temp/{$tempImage}", $height, 0);
                 ImageCache::crop_image(SOFTWARE_HOME . "app/temp/{$tempImage}", $src, $width, $height, $head);
             } else {
                 if ($i_width > $i_height) {
                     ImageCache::resize_image($file, SOFTWARE_HOME . "app/temp/{$tempImage}", 0, $height);
                 } else {
                     ImageCache::resize_image($file, SOFTWARE_HOME . "app/temp/{$tempImage}", $width, 0);
                 }
                 ImageCache::crop_image(SOFTWARE_HOME . "app/temp/{$tempImage}", $src, $width, $height, $head);
             }
         }
         unlink(SOFTWARE_HOME . "app/temp/{$tempImage}");
     }
     return $src;
 }