/** * 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 array with the height & width * * @param int $size size * @param int $width width * @param int $height height * @param int $cw crop width * @param int $ch crop height * @param int $cx crop x axis * @param int $cy crop y axis * @param $image object the image for which the size is desired. NULL means the current image * @return array */ function getSizeCustomImage($size, $width = NULL, $height = NULL, $cw = NULL, $ch = NULL, $cx = NULL, $cy = NULL, $image = NULL) { global $_zp_current_image; if (is_null($image)) { $image = $_zp_current_image; } if (is_null($image)) { return false; } $h = $image->getHeight(); $w = $image->getWidth(); if (isImageVideo($image)) { // size is determined by the player return array($w, $h); } //if we set width/height we are cropping and those are the sizes already if (is_null($size) && !is_null($width) && !is_null($height)) { return array($width, $height); } $side = getOption('image_use_side'); $us = getOption('image_allow_upscale'); $args = getImageParameters(array($size, $width, $height, $cw, $ch, $cx, $cy, NULL, NULL, NULL, NULL, NULL, NULL, NULL), $image->album->name); @(list($size, $width, $height, $cw, $ch, $cx, $cy, $quality, $thumb, $crop, $thumbstandin, $passedWM, $adminrequest, $effects) = $args); if (!empty($size)) { $dim = $size; $width = $height = false; } else { if (!empty($width)) { $dim = $width; $size = $height = false; } else { if (!empty($height)) { $dim = $height; $size = $width = false; } else { $dim = 1; } } } if ($w == 0) { $hprop = 1; } else { $hprop = round($h / $w * $dim); } if ($h == 0) { $wprop = 1; } else { $wprop = round($w / $h * $dim); } if ($size && ($side == 'longest' && $h > $w) || $side == 'height' || $side == 'shortest' && $h < $w || $height) { // Scale the height $newh = $dim; $neww = $wprop; } else { // Scale the width $neww = $dim; $newh = $hprop; } if (!$us && $newh >= $h && $neww >= $w) { return array($w, $h); } else { if ($cw && $cw < $neww) { $neww = $cw; } if ($ch && $ch < $newh) { $newh = $ch; } if ($size && $ch && $cw) { $neww = $cw; $newh = $ch; } return array($neww, $newh); } }
/** * 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; } if ($thumbStandin & 1) { $args = array($size, $width, $height, $cropw, $croph, $cropx, $cropy, NULL, $thumbStandin, NULL, $thumbStandin, NULL, NULL, NULL); if ($this->objectsThumb == NULL) { $filename = makeSpecialImageName($this->getThumbImageFile()); if (!getOption('video_watermark_default_images')) { $args[11] = '!'; } $mtime = NULL; } else { $filename = filesystemToInternal($this->objectsThumb); $mtime = filemtime(ALBUM_FOLDER_SERVERPATH . '/' . internalToFilesystem($this->imagefolder) . '/' . $this->objectsThumb); } return getImageURI($args, $this->album->name, $filename, $this->filemtime); } else { $args = getImageParameters(array($size, $width, $height, $cropw, $croph, $cropx, $cropy, NULL, $thumbStandin, NULL, $thumbStandin, $wmt, NULL, $effects), $this->album->name); $filename = $this->filename; return getImageURI($args, $this->album->name, $filename, $this->filemtime); } }
function loadAlbum($album) { global $_zp_current_album, $_zp_current_image, $_zp_gallery, $custom, $enabled; $subalbums = $album->getAlbums(); $started = false; $tcount = $count = 0; foreach ($subalbums as $folder) { $subalbum = newAlbum($folder); if (!$subalbum->isDynamic()) { $tcount = $tcount + loadAlbum($subalbum); } } $theme = $_zp_gallery->getCurrentTheme(); $id = 0; $parent = getUrAlbum($album); $albumtheme = $parent->getAlbumTheme(); if (!empty($albumtheme)) { $theme = $albumtheme; $id = $parent->getID(); } loadLocalOptions($id, $theme); $_zp_current_album = $album; if ($album->getNumImages() > 0) { echo "<br />" . $album->name . ' '; while (next_image(true)) { if (isImagePhoto($_zp_current_image)) { $countit = 0; if (in_array('*', $enabled)) { $uri = getFullImageURL(NULL, 'Protected view'); if (strpos($uri, 'full-image.php?') !== false) { if (!($count + $countit)) { echo "{ "; } else { echo ' | '; } $countit = 1; ?> <a href="<?php echo html_encode($uri); ?> &debug"> <?php echo '<img src="' . html_encode(pathurlencode($uri)) . '" height="30" width="30" alt="X" />' . "\n"; ?> </a> <?php } } foreach ($custom as $key => $cacheimage) { if (in_array($key, $enabled)) { $size = isset($cacheimage['image_size']) ? $cacheimage['image_size'] : NULL; $width = isset($cacheimage['image_width']) ? $cacheimage['image_width'] : NULL; $height = isset($cacheimage['image_height']) ? $cacheimage['image_height'] : NULL; $thumbstandin = isset($cacheimage['thumb']) ? $cacheimage['thumb'] : NULL; if ($special = $thumbstandin === true) { list($special, $cw, $ch, $cx, $cy) = $_zp_current_image->getThumbCropping($size, $width, $height); } if (!$special) { $cw = isset($cacheimage['crop_width']) ? $cacheimage['crop_width'] : NULL; $ch = isset($cacheimage['crop_height']) ? $cacheimage['crop_height'] : NULL; $cx = isset($cacheimage['crop_x']) ? $cacheimage['crop_x'] : NULL; $cy = isset($cacheimage['crop_y']) ? $cacheimage['crop_y'] : NULL; } $effects = isset($cacheimage['gray']) ? $cacheimage['gray'] : NULL; if (isset($cacheimage['wmk'])) { $passedWM = $cacheimage['wmk']; } else { if ($thumbstandin) { $passedWM = getWatermarkParam($_zp_current_image, WATERMARK_THUMB); } else { $passedWM = getWatermarkParam($_zp_current_image, WATERMARK_IMAGE); } } if (isset($cacheimage['maxspace'])) { getMaxSpaceContainer($width, $height, $_zp_current_image, $thumbstandin); } $args = array($size, $width, $height, $cw, $ch, $cx, $cy, NULL, $thumbstandin, NULL, $thumbstandin, $passedWM, NULL, $effects); $args = getImageParameters($args, $album->name); $uri = getImageURI($args, $album->name, $_zp_current_image->filename, $_zp_current_image->filemtime); if (strpos($uri, 'i.php?') !== false) { if (!($count + $countit)) { echo "{ "; } else { echo ' | '; } $countit = 1; ?> <a href="<?php echo html_encode($uri); ?> &debug"> <?php if ($thumbstandin) { 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 } } } $count = $count + $countit; } } if ($count) { echo ' } '; } printf(ngettext('[%u image]', '[%u images]', $count), $count); echo "<br />\n"; } return $count + $tcount; }
function getIPSizedImage($size, $image) { $wmt = getWatermarkParam($image, WATERMARK_IMAGE); $args = getImageParameters(array($size, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, $wmt), $image->album->name); return getImageProcessorURI($args, $image->album->name, $image->filename); }
/** * 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); } }
/** * 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; } }
} $args = getImageArgs($_GET); $adminrequest = $args[12]; if ($forbidden = getOption('image_processor_flooding_protection') && (!isset($_GET['check']) || $_GET['check'] != sha1(HASH_SEED . serialize($args)))) { // maybe it was from the tinyZenpage javascript which does not know better! zp_session_start(); $forbidden = !isset($_SESSION['adminRequest']) || $_SESSION['adminRequest'] != @$_COOKIE['zp_user_auth']; } 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);
/** * 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); } } }
/** * Get a default-sized thumbnail of this image. * * @return string */ function getThumb($type = 'image', $wmt = NULL) { $ts = getOption('thumb_size'); if (getOption('thumb_crop')) { $sw = getOption('thumb_crop_width'); $sh = getOption('thumb_crop_height'); list($custom, $cw, $ch, $cx, $cy) = $this->getThumbCropping($ts, $sw, $sh); if ($custom) { return $this->getCustomImage(NULL, $sw, $sh, $cw, $ch, $cx, $cy, true); } } else { $sw = $sh = NULL; } if (empty($wmt)) { $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); return getImageURI($args, $this->album->name, $this->filename, $this->filemtime); }
/** * Returns a link to a custom sized version of he current image * * @param int $size size * @param int $width width * @param int $height height * @param int $cw crop width * @param int $ch crop height * @param int $cx crop x axis * @param int $cy crop y axis * @return string */ function getSizeCustomImage($size, $width = NULL, $height = NULL, $cw = NULL, $ch = NULL, $cx = NULL, $cy = NULL) { if (!in_context(ZP_IMAGE)) { return false; } global $_zp_current_image, $_zp_flash_player; if (is_null($_zp_current_image)) { return false; } $h = $_zp_current_image->getHeight(); $w = $_zp_current_image->getWidth(); if (isImageVideo()) { // size is determined by the player return array($w, $h); } $h = $_zp_current_image->getHeight(); $w = $_zp_current_image->getWidth(); $side = getOption('image_use_side'); $us = getOption('image_allow_upscale'); $args = getImageParameters(array($size, $width, $height, $cw, $ch, $cx, $cy, null)); @(list($size, $width, $height, $cw, $ch, $cx, $cy, $quality, $thumb, $crop, $thumbstandin, $thumbWM, $adminrequest) = $args); if (!empty($size)) { $dim = $size; $width = $height = false; } else { if (!empty($width)) { $dim = $width; $size = $height = false; } else { if (!empty($height)) { $dim = $height; $size = $width = false; } else { $dim = 1; } } } if ($w == 0) { $hprop = 1; } else { $hprop = round($h / $w * $dim); } if ($h == 0) { $wprop = 1; } else { $wprop = round($w / $h * $dim); } if ($size && ($side == 'longest' && $h > $w) || $side == 'height' || $side == 'shortest' && $h < $w || $height) { // Scale the height $newh = $dim; $neww = $wprop; } else { // Scale the width $neww = $dim; $newh = $hprop; } if (!$us && $newh >= $h && $neww >= $w) { return array($w, $h); } else { if ($cw && $cw < $neww) { $neww = $cw; } if ($ch && $ch < $newh) { $newh = $ch; } if ($size && $ch && $cw) { $neww = $cw; $newh = $ch; } return array($neww, $newh); } }
} else { $args[] = NULL; } $argh[] = NULL; //9 crop $args[] = NULL; //10 thumb standin if (isset($_GET['wmt']) && !$adminrequest) { //11 $args[] = $_GET['wmt']; } else { $args[] = NULL; } $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) == '') {