Example #1
0
 public static function show($serverPath, $fullUrl, $path, $filename, $destWidth = 64, $destHeight = 64, $ratio = RatioType::SMART, $compression = 10, $canZoom = false)
 {
     if (substr($path, 0, 1) == '/') {
         $path = substr($path, 1);
     }
     $fullpath = $serverPath . $path;
     list($path, $filename) = self::validateFilename($serverPath, $path, $filename);
     list($srcWidth, $srcHeight) = getimagesize($fullpath . $filename);
     $extension = File::getExtension($filename);
     list($calcWidth, $calcHeight) = self::getDimensions($srcWidth, $srcHeight, $destWidth, $destHeight, $ratio, $canZoom);
     // Crop
     $x = 0;
     $y = 0;
     if ($ratio == RatioType::SMART) {
         if ($calcWidth == $destWidth) {
             $srcHeight *= $destHeight / $calcHeight;
             $y = ($calcHeight - $destHeight) * ($srcHeight / $destHeight) / 2;
         } else {
             if ($calcHeight == $destHeight) {
                 $srcWidth *= $destWidth / $calcWidth;
                 $x = ($calcWidth - $destWidth) * ($srcWidth / $destWidth) / 2;
             }
         }
     } else {
         $destWidth = $calcWidth;
         $destHeight = $calcHeight;
     }
     $compression = self::getCompression($extension, $compression);
     // set new filename
     $newFilename = File::getNewFilename($filename, $destWidth, $destHeight, $ratio, $compression);
     self::create($serverPath, $path, $filename, $x, $y, $srcWidth, $srcHeight, $newFilename, $destWidth, $destHeight, $compression);
     return 'http://' . $fullUrl . $path . $newFilename;
 }