Пример #1
0
 /**
  * Creates a thumbnail of an image, if it doesn't exits
  *
  *
  * @param String $imageUrl - The image Url
  * @param Mixed $width - String / Integer
  * @param Mixed $height - String / Integer
  * @param boolean: False: resizes the image to the exact porportions (aspect ratio not preserved). True: preserves aspect ratio, only resises if image is bigger than specified measures
  *
  * @return String - the thumbnail URL
  */
 function onTheFly(phmagick $p, $imageUrl, $width, $height, $exactDimentions = false, $webPath = '', $physicalPath = '')
 {
     //convert web path to physical
     $basePath = str_replace($webPath, $physicalPath, dirname($imageUrl));
     $sourceFile = $basePath . '/' . basename($imageUrl);
     //naming the new thumbnail
     $thumbnailFile = $basePath . '/' . $width . '_' . $height . '_' . basename($imageUrl);
     $P->setSource($sourceFile);
     $p->setDestination($thumbnailFile);
     if (!file_exists($thumbnailFile)) {
         $p->resize($p, $width, $height, $exactDimentions);
     }
     if (!file_exists($thumbnailFile)) {
         //if there was an error, just use original file
         $thumbnailFile = $sourceFile;
     }
     //returning the thumbnail url
     return str_replace($physicalPath, $webPath, $thumbnailFile);
 }