/** * @param $category * @param $example * @param $imageFunction * @param \ImagickDemo\Control $control * @param \ImagickDemo\Example $exampleController * @internal param array $customImageParams * @return JsonResponse */ public function getImageJobStatus(PageInfo $pageInfo, Control $control, Example $exampleController) { $data = []; $customImageParams = $exampleController->getCustomImageParams(); $fullParams = $control->getFullParams($customImageParams); $filename = getImageCacheFilename($pageInfo, $fullParams); $data['filename'] = $filename; $data['finished'] = false; $data['params'] = $fullParams; foreach (getKnownExtensions() as $extension) { if (file_exists($filename . '.' . $extension) == true) { $data['finished'] = true; break; } } return new JsonBody($data); }
/** * Get a custom sized version of this image based on the parameters. * * @param string $alt Alt text for the url * @param int $size size * @param int $width width * @param int $height height * @param int $cropw crop width * @param int $croph crop height * @param int $cropx crop x axis * @param int $cropy crop y axis * @param string $class Optional style class * @param string $id Optional style id * @param bool $thumbStandin set true to inhibit watermarking * @return string */ function getCustomImage($size, $width, $height, $cropw, $croph, $cropx, $cropy, $thumbStandin = false) { if ($thumbStandin & 1) { if ($this->objectsThumb == NULL) { $filename = makeSpecialImageName($this->getThumbImageFile()); $path = ZENFOLDER . '/i.php?a=' . urlencode($this->album->name) . '&i=' . urlencode($filename); return WEBPATH . "/" . $path . ($size ? "&s={$size}" : "") . ($width ? "&w={$width}" : "") . ($height ? "&h={$height}" : "") . ($cropw ? "&cw={$cropw}" : "") . ($croph ? "&ch={$croph}" : "") . ($cropx ? "&cx={$cropx}" : "") . ($cropy ? "&cy={$cropy}" : "") . "&t=true"; } else { $filename = $this->objectsThumb; $wmt = getOption(get_class($this) . '_watermark'); if ($wmt) { $wmt = '&wmt=' . $wmt; } $cachefilename = getImageCacheFilename($alb = $this->album->name, $filename, getImageParameters(array($size, $width, $height, $cropw, $croph, $cropx, $cropy, NULL, NULL, NULL, $thumbStandin, NULL, NULL))); if (file_exists(SERVERCACHE . $cachefilename) && filemtime(SERVERCACHE . $cachefilename) > $this->filemtime) { return WEBPATH . substr(CACHEFOLDER, 0, -1) . pathurlencode(imgSrcURI($cachefilename)); } else { $path = ZENFOLDER . '/i.php?a=' . urlencode($alb) . '&i=' . urlencode($filename); if (substr($path, 0, 1) == "/") { $path = substr($path, 1); } return WEBPATH . "/" . $path . ($size ? "&s={$size}" : "") . ($width ? "&w={$width}" : "") . ($height ? "&h={$height}" : "") . ($cropw ? "&cw={$cropw}" : "") . ($croph ? "&ch={$croph}" : "") . ($cropx ? "&cx={$cropx}" : "") . ($cropy ? "&cy={$cropy}" : "") . "&t=true" . $wmt; } } } else { $filename = $this->filename; $cachefilename = getImageCacheFilename($this->album->name, $filename, getImageParameters(array($size, $width, $height, $cropw, $croph, $cropx, $cropy, NULL, NULL, NULL, $thumbStandin, NULL, NULL))); if (file_exists(SERVERCACHE . $cachefilename) && filemtime(SERVERCACHE . $cachefilename) > $this->filemtime) { return WEBPATH . substr(CACHEFOLDER, 0, -1) . pathurlencode(imgSrcURI($cachefilename)); } else { return WEBPATH . '/' . ZENFOLDER . '/i.php?a=' . urlencode($this->album->name) . '&i=' . urlencode($filename) . ($size ? "&s={$size}" : "") . ($width ? "&w={$width}" : "") . ($height ? "&h={$height}" : "") . ($cropw ? "&cw={$cropw}" : "") . ($croph ? "&ch={$croph}" : "") . ($cropx ? "&cx={$cropx}" : "") . ($cropy ? "&cy={$cropy}" : ""); } } }
/** * * Returns an URI to the image: * * If the image is not cached, the uri will be to the image processor * If the image is cached then the uri will depend on the site option for * cache serving. If the site is set for open cache the uri will point to * the cached image. If the site is set for protected cache the uri will * point to the image processor (which will serve the image from the cache.) * NOTE: this latter implies added overhead for each and every image fetch! * * @param array $args * @param string $album the album name * @param string $image the image name * @param int $mitme mtime of the image * @return string */ function getImageURI($args, $album, $image, $mtime) { $cachefilename = getImageCacheFilename($album, $image, $args); if (OPEN_IMAGE_CACHE && file_exists(SERVERCACHE . $cachefilename) && (!$mtime || filemtime(SERVERCACHE . $cachefilename) >= $mtime)) { return WEBPATH . '/' . CACHEFOLDER . imgSrcURI($cachefilename); } else { return getImageProcessorURI($args, $album, $image); } }
/** * Returns an url to the password protected/watermarked current image * * @param object $image optional image object overrides the current image * @param string $disposal set to override the 'protect_full_image' option * @return string * */ function getProtectedImageURL($image = NULL, $disposal = NULL) { global $_zp_current_image; if (is_null($disposal)) { $disposal = getOption('protect_full_image'); } if ($disposal == 'No access') { return NULL; } if (is_null($image)) { if (!in_context(ZP_IMAGE)) { return false; } if (is_null($_zp_current_image)) { return false; } $image = $_zp_current_image; } $album = $image->getAlbum(); $watermark_use_image = getWatermarkParam($image, WATERMARK_FULL); if (!empty($watermark_use_image)) { $wmt = $watermark_use_image; } else { $wmt = false; } $args = array('FULL', NULL, NULL, NULL, NULL, NULL, NULL, (int) getOption('full_image_quality'), NULL, NULL, NULL, $wmt, false, NULL, NULL); $cache_file = getImageCacheFilename($album->name, $image->filename, $args); $cache_path = SERVERCACHE . $cache_file; if ($disposal != 'Download' && OPEN_IMAGE_CACHE && file_exists($cache_path)) { return WEBPATH . '/' . CACHEFOLDER . pathurlencode(imgSrcURI($cache_file)); } else { if ($disposal == 'Unprotected') { return getImageURI($args, $album->name, $image->filename, $image->filemtime); } else { $params = '&q=' . getOption('full_image_quality'); if (!empty($watermark_use_image)) { $params .= '&wmk=' . $watermark_use_image; } if ($disposal) { $params .= '&dsp=' . $disposal; } $params .= '&check=' . sha1(HASH_SEED . serialize($args)); if (is_array($image->filename)) { $album = dirname($image->filename['source']); $image = basename($image->filename['source']); } else { $album = $album->name; $image = $image->filename; } return WEBPATH . '/' . ZENFOLDER . '/full-image.php?a=' . $album . '&i=' . $image . $params; } } }
if (isset($args[10])) { echo '<img src="' . html_encode(pathurlencode($uri)) . '" height="15" width="15" alt="x" />' . "\n"; } else { echo '<img src="' . html_encode(pathurlencode($uri)) . '" height="20" width="20" alt="X" />' . "\n"; } ?> </a> <?php } break; } } if ($missing) { recordMissing($table, $row, $image); } $cache_file = '{*WEBPATH*}/' . CACHEFOLDER . getImageCacheFilename(dirname($image), basename($image), $args); if ($match != $cache_file) { //need to update the record. $row[$field] = updateCacheName($row[$field], $match, $cache_file); $updated = true; } } } if ($updated) { $sql = 'UPDATE ' . prefix($table) . ' SET `' . $field . '`=' . db_quote($row[$field]) . ' WHERE `id`=' . $row['id']; query($sql); } } } } }
function directCustomImageCallable(PageInfo $pageInfo, \Auryn\Injector $injector, $params) { $imageFunction = CategoryInfo::getCustomImageFunctionName($pageInfo); $filename = getImageCacheFilename($pageInfo, $params); global $imageType; ob_start(); $injector->execute($imageFunction); if ($imageType == null) { ob_end_clean(); throw new \Exception("imageType not set, can't cache image correctly."); } $imageData = ob_get_contents(); ob_end_clean(); return new DataBody($filename, $imageData, "image/" . $imageType); }
$args[] = $adminrequest; //12 $args = getImageParameters($args); list($size, $width, $height, $cw, $ch, $cx, $cy, $quality, $thumb, $crop, $thumbstandin, $thumbWM, $adminrequest) = $args; $allowWatermark = !$thumb && !$adminrequest; if ($debug) { imageDebug($album, $image, $args); } } else { // No image parameters specified or are out of bounds; return the original image. //TODO: this will fail when the album folder is external to zp. Maybe should force the sizes within bounds. header("Location: " . getAlbumFolder(FULLWEBPATH) . pathurlencode(FilesystemToUTF8($album)) . "/" . rawurlencode(filesystemToUTF8($image))); return; } // Construct the filename to save the cached image. $newfilename = getImageCacheFilename(FilesystemToUTF8($album), filesystemToUTF8($image), $args); $newfile = SERVERCACHE . $newfilename; if (trim($album) == '') { $imgfile = getAlbumFolder() . $image; } else { $imgfile = getAlbumFolder() . $album . '/' . $image; } /** Check for possible problems *********** ******************************************/ // Make sure the cache directory is writable, attempt to fix. Issue a warning if not fixable. if (!is_dir(SERVERCACHE)) { @mkdir(SERVERCACHE, CHMOD_VALUE); @chmod(SERVERCACHE, CHMOD_VALUE); if (!is_dir(SERVERCACHE)) { imageError(gettext("The cache directory does not exist. Please create it and set the permissions to 0777."), 'err-cachewrite.gif'); }
/** * @param $category * @param $example * @param $imageFunction * @param \ImagickDemo\Control $control * @param \ImagickDemo\Example $exampleController * @internal param array $customImageParams * @return JsonResponse */ function getImageJobStatus($category, $example, $imageFunction, \ImagickDemo\Control $control, \ImagickDemo\Example $exampleController) { $data = []; $customImageParams = $exampleController->getCustomImageParams(); $fullParams = $control->getFullParams($customImageParams); $filename = getImageCacheFilename($category, $example, $fullParams); $data['filename'] = $filename; $data['finished'] = false; $data['params'] = $fullParams; foreach (getKnownExtensions() as $extension) { if (file_exists($filename . '.' . $extension) == true) { $data['finished'] = true; break; } } return new JsonResponse($data); }
/** * Get a default-sized thumbnail of this image. * * @return string */ function getThumb($type = 'image') { $ts = getOption('thumb_size'); if (getOption('thumb_crop')) { list($custom, $sw, $sh, $cw, $ch, $cx, $cy) = $this->getThumbCropping($type); if ($custom) { return $this->getCustomImage(NULL, $sw, $sh, $cw, $ch, $cx, $cy, true); } } else { $sw = $sh = NULL; } $filename = $this->filename; $wmt = getWatermarkParam($this, WATERMARK_THUMB); $args = getImageParameters(array($ts, NULL, NULL, $sw, $sh, NULL, NULL, NULL, true, NULL, true, $wmt, NULL, NULL), $this->album->name); $cachefilename = getImageCacheFilename($alb = $this->album->name, $filename, $args); if (file_exists(SERVERCACHE . $cachefilename) && filemtime(SERVERCACHE . $cachefilename) > $this->filemtime) { return WEBPATH . '/' . CACHEFOLDER . pathurlencode(imgSrcURI($cachefilename)); } else { return getImageProcessorURI($args, $this->album->name, $this->filename); } }
} if (!isset($_GET['s']) && !isset($_GET['w']) && !isset($_GET['h'])) { // No image parameters specified if (getOption('album_folder_class') !== 'external') { header("Location: " . getAlbumFolder(FULLWEBPATH) . pathurlencode(filesystemToInternal($album)) . "/" . rawurlencode(filesystemToInternal($image))); return; } } $args = getImageParameters($args, filesystemToInternal($album)); list($size, $width, $height, $cw, $ch, $cx, $cy, $quality, $thumb, $crop, $thumbstandin, $passedWM, $adminrequest, $effects) = $args; if (DEBUG_IMAGE) { debugLog("i.php({$ralbum}, {$rimage}): \$size={$size}, \$width={$width}, \$height={$height}, \$cw={$cw}, \$ch={$ch}, \$cx={$cx}, \$cy={$cy}, \$quality={$quality}, \$thumb={$thumb}, \$crop={$crop}, \$thumbstandin={$thumbstandin}, \$passedWM={$passedWM}, \$adminrequest={$adminrequest}, \$effects={$effects}"); } $allowWatermark = !$thumb && !$adminrequest; // Construct the filename to save the cached image. $newfilename = getImageCacheFilename(filesystemToInternal($album), filesystemToInternal($image), $args); $newfile = SERVERCACHE . $newfilename; if (trim($album) == '') { $imgfile = ALBUM_FOLDER_SERVERPATH . $image; } else { $imgfile = ALBUM_FOLDER_SERVERPATH . $album . '/' . $image; } if ($debug) { imageDebug($album, $image, $args, $imgfile); } /** Check for possible problems *********** * **************************************** */ // Make sure the cache directory is writable, attempt to fix. Issue a warning if not fixable. if (!is_dir(SERVERCACHE)) { @mkdir(SERVERCACHE, FOLDER_MOD); @chmod(SERVERCACHE, FOLDER_MOD);
public function getFilename() { return getImageCacheFilename($this->pageInfo, $this->params); }
/** * returns a link to the thumbnail for the text file. * * @param string $type 'image' or 'album' * @return string */ function getThumb($type = 'image') { $ts = getOption('thumb_size'); $sw = getOption('thumb_crop_width'); $sh = getOption('thumb_crop_height'); list($custom, $cw, $ch, $cx, $cy) = $this->getThumbCropping($ts, $sw, $sh); $wmt = $this->watermark; if (empty($wmt)) { $wmt = getWatermarkParam($this, WATERMARK_THUMB); } if (is_null($this->objectsThumb)) { $mtime = $cx = $cy = NULL; $filename = makeSpecialImageName($this->getThumbImageFile()); if (!$this->watermarkDefault) { $wmt = '!'; } } else { $filename = filesystemToInternal($this->objectsThumb); $mtime = filemtime(ALBUM_FOLDER_SERVERPATH . '/' . internalToFilesystem($this->imagefolder) . '/' . $this->objectsThumb); } $args = getImageParameters(array($ts, $sw, $sh, $cw, $ch, $cx, $cy, NULL, true, true, true, $wmt, NULL, NULL), $this->album->name); $cachefilename = getImageCacheFilename($alb = $this->album->name, $this->filename, $args); return getImageURI($args, $alb, $filename, $mtime); }
/** * Get a custom sized version of this image based on the parameters. * * @param string $alt Alt text for the url * @param int $size size * @param int $width width * @param int $height height * @param int $cropw crop width * @param int $croph crop height * @param int $cropx crop x axis * @param int $cropy crop y axis * @param string $class Optional style class * @param string $id Optional style id * @param bool $thumbStandin set to true to treat as thumbnail * @param bool $effects ignored * @return string */ function getCustomImage($size, $width, $height, $cropw, $croph, $cropx, $cropy, $thumbStandin = false, $effects = NULL) { if ($thumbStandin) { $wmt = getOption('Video_watermark'); if (empty($wmt)) { $wmt = getWatermarkParam($this, WATERMARK_THUMB); } } else { $wmt = NULL; } $args = getImageParameters(array($size, $width, $height, $cropw, $croph, $cropx, $cropy, NULL, $thumbStandin, NULL, $thumbStandin, $wmt, NULL, $effects), $this->album->name); if ($thumbStandin & 1) { if ($this->objectsThumb == NULL) { $filename = makeSpecialImageName($this->getThumbImageFile()); if (!getOption('video_watermark_default_images')) { $args[11] = '!'; } return getImageProcessorURI($args, $this->album->name, $filename); } else { $filename = $this->objectsThumb; $cachefilename = getImageCacheFilename($alb = $this->album->name, $filename, getImageParameters(array($size, $width, $height, $cropw, $croph, $cropx, $cropy, NULL, $thumbStandin, NULL, $thumbStandin, NULL, NULL, NULL)), $this->album->name); if (file_exists(SERVERCACHE . $cachefilename) && filemtime(SERVERCACHE . $cachefilename) > $this->filemtime) { return WEBPATH . '/' . CACHEFOLDER . pathurlencode(imgSrcURI($cachefilename)); } else { return getImageProcessorURI($args, $this->album->name, $filename); } } } else { $filename = $this->filename; $cachefilename = getImageCacheFilename($this->album->name, $filename, $args); if (file_exists(SERVERCACHE . $cachefilename) && filemtime(SERVERCACHE . $cachefilename) > $this->filemtime) { return WEBPATH . '/' . CACHEFOLDER . pathurlencode(imgSrcURI($cachefilename)); } else { return getImageProcessorURI($args, $this->album->name, $filename); } } }
/** * @param $category * @param $example * @param $imageFunction * @param $params * @return ImagickTask */ public static function create($category, $example, $imageFunction, $params) { $filename = getImageCacheFilename($category, $example, $params); return new \ImagickDemo\Queue\ImagickTask($imageFunction, $params, $filename); }
/** * Returns an url to the password protected/watermarked current image * * @param object $image optional image object overrides the current image * @param string $disposal set to override the 'protect_full_image' option * @return string **/ function getProtectedImageURL($image = NULL, $disposal = NULL) { global $_zp_current_image; if ($disposal == 'No access') { return NULL; } if (is_null($image)) { if (!in_context(ZP_IMAGE)) { return false; } if (is_null($_zp_current_image)) { return false; } $image = $_zp_current_image; } $album = $image->getAlbum(); $wmt = $image->getWatermark(); if (!empty($wmt) || !($image->getWMUse() & WATERMARK_FULL)) { $wmt = NULL; } $args = array('FULL', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, $wmt, NULL); $cache_file = getImageCacheFilename($album->name, $image->filename, $args); $cache_path = SERVERCACHE . $cache_file; if (empty($disposal) && file_exists($cache_path)) { return WEBPATH . '/' . CACHEFOLDER . pathurlencode(imgSrcURI($cache_file)); } else { $params = '&q=' . getOption('full_image_quality'); $watermark_use_image = getWatermarkParam($image, WATERMARK_FULL); if (!empty($watermark_use_image)) { $params .= '&wmk=' . $watermark_use_image; } if ($disposal) { $params .= '&dsp=' . $disposal; } return WEBPATH . '/' . ZENFOLDER . '/full-image.php?a=' . urlencode($album->name) . '&i=' . urlencode($image->filename) . $params; } }
$injector->alias(\ImagickDemo\Navigation\Nav::class, \ImagickDemo\Navigation\CategoryNav::class); $pageInfo = new PageInfo($category, $functionName); $injector->share($pageInfo); $categoryNav = $injector->make(\ImagickDemo\Navigation\CategoryNav::class); $exampleDefinition = CategoryNav::getExampleDefinition($category, $functionName); $function = $exampleDefinition[0]; $controlClass = $exampleDefinition[1]; if (array_key_exists('defaultParams', $exampleDefinition) == true) { foreach ($exampleDefinition['defaultParams'] as $name => $value) { $defaultName = 'default' . ucfirst($name); $injector->defineParam($defaultName, $value); } } createControl($categoryNav, $injector); $pageInfo = new \ImagickDemo\Helper\PageInfo($category, $functionName); $filename = getImageCacheFilename($pageInfo, $params); $extensions = [".jpg", '.jpeg', ".gif", ".png"]; $fileExtension = false; foreach ($extensions as $extension) { $filenameWithExtension = $filename . $extension; if (file_exists($filenameWithExtension) == true) { $fileExtension = $extension; } } if ($fileExtension === false) { echo "File {$filename} does not exist creating.\n"; generateCompare($injector, $functionFullname, $filename); } else { compareFile($injector, $functionFullname, $filename, $fileExtension); } }
// enable this to make the image a download $fp = fopen($image_path, 'rb'); // send the right headers header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); header("Content-Type: {$mimetype}"); header("Content-Length: " . filesize($image_path)); // dump the picture and stop the script fpassthru($fp); fclose($fp); } else { header('Location: ' . $imageobj->getFullImageURL(), true, 301); } exitZP(); } if ($force_cache = getOption('cache_full_image')) { $cache_file = getImageCacheFilename($album, $image, $args); $cache_path = SERVERCACHE . $cache_file; mkdir_recursive(dirname($cache_path), FOLDER_MOD); } else { $cache_file = $album . "/" . stripSuffix($image) . '_FULL.' . $suffix; $cache_path = NULL; } $process = $rotate = false; if (zp_imageCanRotate()) { $rotate = getImageRotation($imageobj); $process = $rotate; } $watermark_use_image = getWatermarkParam($imageobj, WATERMARK_FULL); if ($watermark_use_image == NO_WATERMARK) { $watermark_use_image = ''; } else {
/** * Get a default-sized thumbnail of this image. * * @return string */ function getThumb($type = 'image') { if (getOption('thumb_crop') && !is_null($cy = $this->get('thumbY'))) { $ts = getOption('thumb_size'); $sw = getOption('thumb_crop_width'); $sh = getOption('thumb_crop_height'); $cx = $this->get('thumbX'); $cw = $this->get('thumbW'); $ch = $this->get('thumbH'); // upscale to thumb_size proportions if ($sw == $sh) { // square crop, set the size/width to thumbsize $sw = $sh = $ts; } else { if ($sw > $sh) { $r = $ts / $sw; $sw = $ts; $sh = $sh * $r; } else { $r = $ts / $sh; $sh = $ts; $sh = $r * $sh; } } return $this->getCustomImage(NULL, $sw, $sh, $cw, $ch, $cx, $cy, true); } $filename = $this->filename; $wmt = getOption('Image_watermark'); if ($wmt) { $wmt = '&wmt=' . $wmt; } $cachefilename = getImageCacheFilename($alb = $this->album->name, $filename, getImageParameters(array('thumb'))); if (file_exists(SERVERCACHE . $cachefilename) && filemtime(SERVERCACHE . $cachefilename) > $this->filemtime) { return WEBPATH . substr(CACHEFOLDER, 0, -1) . pathurlencode(imgSrcURI($cachefilename)); } else { if (getOption('mod_rewrite') && empty($wmt) && !empty($alb)) { $path = pathurlencode($alb) . '/' . $type . '/thumb/' . urlencode($filename); } else { $path = ZENFOLDER . '/i.php?a=' . urlencode($this->album->name) . '&i=' . urlencode($filename) . '&s=thumb' . $wmt; if ($type !== 'image') { $path .= '&' . $type . '=true'; } } if (substr($path, 0, 1) == "/") { $path = substr($path, 1); } return WEBPATH . "/" . $path; } }
$injector->defineParam($name, $value); } $injector->alias(\ImagickDemo\Navigation\Nav::class, \ImagickDemo\Navigation\CategoryNav::class); $injector->define(\ImagickDemo\Navigation\CategoryNav::class, [':category' => $category, ':example' => $functionName]); $categoryNav = $injector->make(\ImagickDemo\Navigation\CategoryNav::class); $exampleDefinition = $categoryNav->getExampleDefinition($category, $functionName); $function = $exampleDefinition[0]; $controlClass = $exampleDefinition[1]; if (array_key_exists('defaultParams', $exampleDefinition) == true) { foreach ($exampleDefinition['defaultParams'] as $name => $value) { $defaultName = 'default' . ucfirst($name); $injector->defineParam($defaultName, $value); } } //delegateAllTheThings($injector, $controlClass); $filename = getImageCacheFilename($category, $functionName . ".compare", $params); $extensions = [".jpg", '.jpeg', ".gif", ".png"]; $fileExtension = false; foreach ($extensions as $extension) { $filenameWithExtension = $filename . $extension; if (file_exists($filenameWithExtension) == true) { $fileExtension = $extension; } } if ($fileExtension === false) { echo "File {$filename} does not exist creating.\n"; generateCompare($injector, $functionFullname, $filename); } else { compareFile($injector, $functionFullname, $filename, $fileExtension); } }
/** * @param $category * @param $example * @param \ImagickDemo\Control $control * @return mixed */ function getCachedImageResponse($category, $example, $params) { $filename = getImageCacheFilename($category, $example, $params); return createFileResponseIfFileExists($filename); }