Beispiel #1
0
/**
 * Vyplni obrazek na maximalni sirku a vysku natvrdo zadanou - muze zvetsovat
 * @param \Imagick $image
 * @param int $width
 * @param int $height
 */
function imagickFill(\Imagick $image, $width, $height)
{
    list($newWidth, $newHeight) = \Nette\Utils\Image::calculateSize($image->getImageWidth(), $image->getImageHeight(), $width, $height, \Nette\Utils\Image::FILL);
    $image->thumbnailImage($newWidth, $newHeight, true, true);
}
Beispiel #2
0
 /**
  * @param string $imgUrl
  * @param int $width
  * @param int $height
  * @param int $crop
  * @return string
  * @register imgOffset
  */
 public function imageOffset($imgUrl, $width, $height = NULL, $crop = NULL)
 {
     $origName = substr($imgUrl, strrpos($imgUrl, '/') + 1);
     $origPath = ($this->domainDir ? $this->domainDir : $this->cacheDir) . $imgUrl;
     if (!is_file($origPath)) {
         return '';
     }
     $ext = pathinfo($imgUrl, PATHINFO_EXTENSION);
     $a = explode('/', $imgUrl);
     array_pop($a);
     $a = implode('/', $a);
     $thumbName = $this->getThumbName($origName, $width, $height, filemtime($origPath), $crop);
     $thumbName = md5(($this->domainDirUrl ? $this->domainDirUrl : $this->cacheDirUrl) . '/' . $a . '/thumbs/' . $thumbName) . ".{$ext}";
     $path = ($this->domainDir ? $this->domainDir : $this->cacheDir) . $a . '/thumbs/' . $thumbName;
     if (file_exists($path)) {
         $size = getimagesize($path);
         $newSize = Image::calculateSize($size[0], $size[1], $width, $height);
         $widthOffset = floor(($width - $newSize[0]) / 2);
         $heightOffset = floor(($height - $newSize[1]) / 2);
         return 'padding: ' . $heightOffset . 'px ' . $widthOffset . 'px;';
     } elseif (file_exists($this->cacheDir . $imgUrl)) {
         $size = getimagesize($this->cacheDir . $imgUrl);
         $newSize = Image::calculateSize($size[0], $size[1], $width, $height);
         $widthOffset = floor(($width - $newSize[0]) / 2);
         $heightOffset = floor(($height - $newSize[1]) / 2);
         return 'padding: ' . $heightOffset . 'px ' . $widthOffset . 'px;';
     }
 }
Beispiel #3
0
 /**
  * @param string $file
  * @param int $modified
  * @param string $path
  * @param int $width
  * @param int $height
  * @param int $flags
  * @return array
  */
 private function getImageAttributes($file, $modified, $path, $width, $height, $flags)
 {
     list($srcWidth, $srcHeight, $type) = getimagesize($file);
     if ($width === NULL && $height === NULL) {
         $width = $imgWidth = $srcWidth;
         $height = $imgHeight = $srcHeight;
     } else {
         if ($flags === Image::EXACT && $width !== NULL && $height !== NULL) {
             $imgWidth = $width;
             $imgHeight = $height;
         } else {
             list($calculateWidth, $calculateHeight) = Image::calculateSize($srcWidth, $srcHeight, $width, $height, $flags);
             $width = $imgWidth = $calculateWidth;
             $height = $imgHeight = $calculateHeight;
         }
     }
     $cacheKey = $path . '/' . pathinfo($file, PATHINFO_FILENAME) . '_' . $imgWidth . 'x' . $imgHeight . '-' . $flags;
     $cacheFile = $this->cache->load($cacheKey, $modified, image_type_to_extension($type, FALSE));
     if (!$cacheFile) {
         $image = Image::fromFile($file);
         $image->resize($width, $height, $flags);
         $image->interlace();
         $cacheFile = $this->cache->save($cacheKey, $image->toString($type), image_type_to_extension($type, FALSE));
     }
     $formatUrl = $this->formatUrl($path, $cacheFile, $modified);
     $imageAttributes = array('src' => $formatUrl, 'width' => $imgWidth, 'height' => $imgHeight);
     return $imageAttributes;
 }