private function thumb_href($source_path, $width, $height) { if (!file_exists($source_path)) { return null; } $name = 'thumb-' . sha1($source_path) . '-' . $width . 'x' . $height . '.jpg'; $thumb_path = $this->thumbs_path . '/' . $name; $thumb_href = $this->thumbs_href . '/' . $name; if (!file_exists($thumb_path) || filemtime($source_path) >= filemtime($thumb_path)) { $image = new Image(); $et = false; if ($this->setup->get('HAS_PHP_EXIF') && $this->context->query_option('thumbnails.exif', false) === true && $height != 0) { $et = @exif_thumbnail($source_path); } if ($et !== false) { file_put_contents($thumb_path, $et); $image->set_source($thumb_path); $image->normalize_exif_orientation($source_path); } else { $image->set_source($source_path); } $image->thumb($width, $height); $image->save_dest_jpeg($thumb_path, 80); } return file_exists($thumb_path) ? $thumb_href : null; }
private function thumb_href($source_abs_path, $mode, $width, $height) { if (!file_exists($source_abs_path)) { return null; } if (!is_dir($this->thumbs_path)) { @mkdir($this->thumbs_path, 0755, true); } $name = "thumb-" . sha1("{$source_abs_path}-{$width}-{$height}-{$mode}") . ".jpg"; $thumb_abs_path = $this->thumbs_path . "/" . $name; $thumb_abs_href = $this->thumbs_href . "/" . $name; if (!file_exists($thumb_abs_path) || filemtime($source_abs_path) >= filemtime($thumb_abs_path)) { $image = new Image(); $et = false; $opts = $this->app->get_options(); if ($opts["thumbnails"]["exif"] === true && function_exists("exif_thumbnail")) { $et = @exif_thumbnail($source_abs_path); } if ($et !== false) { file_put_contents($thumb_abs_path, $et); $image->set_source($thumb_abs_path); $image->normalize_exif_orientation($source_abs_path); } else { $image->set_source($source_abs_path); } $image->thumb($mode, $width, $height); $image->save_dest_jpeg($thumb_abs_path, 80); } return file_exists($thumb_abs_path) ? $thumb_abs_href : null; }
private function thumb_href($source_path, $width, $height) { if (!file_exists($source_path)) { return null; } $name = "thumb-" . sha1("{$source_path}") . "-" . $width . "x" . $height . ".jpg"; $thumb_path = $this->thumbs_path . "/" . $name; $thumb_url = $this->thumbs_href . "/" . $name; if (!file_exists($thumb_path) || filemtime($source_path) >= filemtime($thumb_path)) { $image = new Image(); $et = false; $opts = $this->app->get_options(); if (HAS_PHP_EXIF && $opts["thumbnails"]["exif"] === true && $height != 0) { $et = @exif_thumbnail($source_path); } if ($et !== false) { file_put_contents($thumb_path, $et); $image->set_source($thumb_path); $image->normalize_exif_orientation($source_path); } else { $image->set_source($source_path); } $image->thumb($width, $height); $image->save_dest_jpeg($thumb_path, 80); } return file_exists($thumb_path) ? $thumb_url : null; }
function __construct($image, $isfile = false) { if (!empty($image) || $this->filename !== null) { if (is_readable($this->filename) && function_exists('exif_thumbnail') && in_array(image_type_to_mime_type(exif_imagetype($this->filename)), array('image/jpeg', 'image/tiff'))) { $this->thumb = @exif_thumbnail($this->filename); if (trim($this->thumb) == "") { $this->thumb = NULL; } } $this->classname = get_class($this); if ($isfile) { $this->filename = $image; } else { $this->data = $image; } } }
function ExtractEXIFgetImageSize() { if ($this->getimagesizeinfo = @GetImageSize($this->sourceFilename)) { $this->source_width = $this->getimagesizeinfo[0]; $this->source_height = $this->getimagesizeinfo[1]; if (function_exists('exif_thumbnail') && $this->getimagesizeinfo[2] == 2) { // Extract EXIF info from JPEGs $this->exif_thumbnail_width = ''; $this->exif_thumbnail_height = ''; $this->exif_thumbnail_type = ''; // The parameters width, height and imagetype are available since PHP v4.3.0 if (phpthumb_functions::version_compare_replacement(phpversion(), '4.3.0', '>=')) { $this->exif_thumbnail_data = @exif_thumbnail($this->sourceFilename, $this->exif_thumbnail_width, $this->exif_thumbnail_height, $this->exif_thumbnail_type); } else { // older versions of exif_thumbnail output an error message but NOT return false on failure ob_start(); $this->exif_thumbnail_data = exif_thumbnail($this->sourceFilename); $exit_thumbnail_error = ob_get_contents(); ob_end_clean(); if (empty($exit_thumbnail_error) && !empty($this->exif_thumbnail_data)) { if ($gdimg_exif_temp = $this->ImageCreateFromStringReplacement($this->exif_thumbnail_data, false)) { $this->exif_thumbnail_width = ImageSX($gdimg_exif_temp); $this->exif_thumbnail_height = ImageSY($gdimg_exif_temp); $this->exif_thumbnail_type = 2; // (2 == JPEG) before PHP v4.3.0 only JPEG format EXIF thumbnails are returned unset($gdimg_exif_temp); } else { $this->ErrorImage('Failed - $this->ImageCreateFromStringReplacement($this->exif_thumbnail_data) in ' . __FILE__ . ' on line ' . __LINE__); } } } } // see if EXIF thumbnail can be used directly with no processing if (!empty($this->exif_thumbnail_data)) { while (true) { if (!empty($this->xto)) { if (isset($this->w) && $this->w != $this->exif_thumbnail_width) { break; } if (isset($this->h) && $this->h != $this->exif_thumbnail_height) { break; } $CannotBeSetParameters = array('sx', 'sy', 'sh', 'sw', 'bw', 'bg', 'bc', 'usa', 'usr', 'ust', 'wmf', 'wmp', 'wmm', 'wma'); foreach ($CannotBeSetParameters as $parameter) { if (!empty($this->{$parameter})) { break 2; } } } if (!empty($this->xto) && empty($this->phpThumbDebug)) { // write cached file $ImageTypesLookup = array(2 => 'jpeg'); // EXIF thumbnails are (currently?) only availble from JPEG source images if (is_dir($this->config_cache_directory) && is_writable($this->config_cache_directory) && isset($ImageTypesLookup[$this->exif_thumbnail_type])) { $cache_filename = $this->GenerateCachedFilename($ImageTypesLookup[$this->exif_thumbnail_type]); if (is_writable($cache_filename)) { if ($fp_cached = @fopen($cache_filename, 'wb')) { fwrite($fp_cached, $this->exif_thumbnail_data); fclose($fp_cached); } } } if ($mime_type = ImageTypeToMIMEtype($this->exif_thumbnail_type)) { header('Content-type: ' . $mime_type); echo $this->exif_thumbnail_data; exit; } else { $this->ErrorImage('ImageTypeToMIMEtype(' . $this->exif_thumbnail_type . ') failed in ' . __FILE__ . ' on line ' . __LINE__); } } break; } } if ($this->config_max_source_pixels > 0 && $this->source_width * $this->source_height > $this->config_max_source_pixels) { // Source image is larger than would fit in available PHP memory if (!empty($this->exif_thumbnail_data)) { // EXIF thumbnail exists, and will be use as source image $this->gdimg_source = $this->ImageCreateFromStringReplacement($this->exif_thumbnail_data); $this->source_width = $this->exif_thumbnail_width; $this->source_height = $this->exif_thumbnail_height; // override allow-enlarging setting if EXIF thumbnail is the only source available // otherwise thumbnails larger than the EXIF thumbnail will be created at EXIF size $this->config_output_allow_enlarging = true; } else { // EXIF thumbnail is unavailable // if ImageMagick is installed, use it to thumbnail, // otherwise no choice but to abort if ($this->ImageMagickThumbnailToGD()) { // excellent, we have a thumbnail } else { $this->ErrorImage('Source image is more than ' . sprintf('%1.1f', $this->config_max_source_pixels / 1000000) . ' megapixels - insufficient memory.' . "\n" . 'EXIF thumbnail unavailable.'); } } } } return true; }
// access a file in a user's directory require_once $_SERVER['DOCUMENT_ROOT'] . '/include/main_func.php'; auth(); $file = IMAGEBASEDIR . $_GET['file']; preg_match("/^\\d{1,11}\\//", $_GET['file'], $project); $project = str_replace('/', '', $project[0]); $user = $_SESSION['user_id']; // apply your logic here $userCanDownloadThisFile = in_array($project, $_SESSION['projects']); if (file_exists($file) && $userCanDownloadThisFile && underPath($file)) { $ext = pathinfo($file, PATHINFO_EXTENSION); if (array_key_exists('thumb', $_GET) && in_array($ext, array('jpg', 'gif', 'png')) && filesize($file) > 5000) { header('Content-Type: image/jpeg'); if ($ext == 'jpg') { echo exif_thumbnail($file); } else { if ($ext == 'png' || $ext == 'gif') { $img = $ext == 'png' ? imagecreatefrompng($file) : imagecreatefromgif($file); $width = imagesx($img); $height = imagesy($img); $new_height = 100; $new_width = $width * $new_height / $height; $thumb_img = imagecreatetruecolor($new_width, $new_height); imagecopyresampled($thumb_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height); imagedestroy($img); imagejpeg($thumb_img); imagedestroy($thumb_img); } } } else {
<?php /* test1.jpg is a 1*1 image that does not contain any Exif/Comment information test2.jpg is the same image but contains Exif/Comment information and a copy of test1.jpg as a thumbnail. */ $infile = dirname(__FILE__) . '/test1.jpg'; echo md5_file($infile) . '_' . filesize($infile); $thumb = exif_thumbnail(dirname(__FILE__) . '/test2.jpg'); echo " == "; echo md5($thumb) . '_' . strlen($thumb); echo "\n";
<?php Header('Content-type: image/tiff'); echo exif_thumbnail('p0004557.jpg');
$target_path = $target_path . basename($_FILES['archivo']['name']); if (move_uploaded_file($_FILES['archivo']['tmp_name'], $target_path)) { $jsondata['success'] = "El archivo " . basename($_FILES['archivo']['name']) . " ha sido subido"; } else { $jsondata['error'] = error_get_last(); //echo "Ha ocurrido un error, trate de nuevo!"; } $archivador = "./images/" . $jsondata['nombre_archivo']; //$v_imagen = $target_path.$_FILES['archivo']['name']; $v_imagen = "../images/" . $jsondata['nombre_archivo']; $jsondata['v_imagen'] = $v_imagen; // Generar thumbnail. $v_ancho_imagen = 1234; $v_alto_imagen = 800; $v_tipo_imagen = 'jpg'; $v_thumbnail = exif_thumbnail($v_imagen, $v_ancho_imagen, $v_alto_imagen, $v_tipo_imagen); $v_exif = exif_read_data($v_imagen); $v_longitud = getGps($v_exif["GPSLongitude"], $v_exif['GPSLongitudeRef']); $v_latitud = getGps($v_exif["GPSLatitude"], $v_exif['GPSLatitudeRef']); $jsondata['latitud'] = "La latitud de la imagen es: " . $v_latitud; $jsondata['longitud'] = "La longitud de la imagen es: " . $v_longitud; $query = "INSERT INTO TIO_IMAGENES(direccion_imagen,latitud_imagen,longitud_imagen) VALUES('{$archivador}',{$v_latitud},{$v_longitud})"; if ($conn->query($query) === TRUE) { $jsondata['success'] = "El archivo se ha subido correctamente al servidor"; } else { $jsondata['success'] = "Error al subir archivo: " . $conn->error; } function getGps($exifCoord, $hemi) { $degrees = count($exifCoord) > 0 ? gps2Num($exifCoord[0]) : 0; $minutes = count($exifCoord) > 1 ? gps2Num($exifCoord[1]) : 0;
/** * Extracts the embedded thumbnail picture of a jpeg or tiff image * * @return string thumbnail */ protected function extractEmbeddedThumbnail() { if (!function_exists('exif_thumbnail')) { return false; } $width = $height = $type = 0; $thumbnail = @exif_thumbnail($this->sourceFile, $width, $height, $type); if ($thumbnail && $type && $width && $height) { // resize the extracted thumbnail again if necessary // (normally the thumbnail size is set to 160px // which is recommended in EXIF >2.1 and DCF) $this->mimeType = image_type_to_mime_type($type); if (!$this->checkSize($width, $height)) { // get temporary file name $this->sourceFile = FileUtil::getTemporaryFilename('thumbnail_'); // create tmp file $tmpFile = new File($this->sourceFile); $tmpFile->write($thumbnail); $tmpFile->close(); unset($thumbnail, $tmpFile); // resize tmp file again return $this->makeThumbnail(true); } return $thumbnail; } return false; }
public function getThumbnail() { return exif_thumbnail($this->sFilename); }
/** * Load exif thumbnail * We can load thumbnail only if we want because in loadExifData() in * function read_exif_data() parameter $read_thumbnail = false */ protected function loadExifThumbnail() { if (is_array($this->exifData) && array_key_exists('THUMBNAIL', $this->exifData)) { // read an exif data // exif_thumbnail($filename, $width, $height, $imagetype) $this->exifThumbnail = exif_thumbnail($this->file, $this->tnWidth, $this->tnHeight, $this->tnType); } }
<?php if (array_key_exists('file', $_REQUEST)) { $image = exif_thumbnail($_REQUEST['file'], $width, $height, $type); } else { $image = false; } if ($image !== false) { header('Content-type: ' . image_type_to_mime_type($type)); echo $image; exit; } else { // no thumbnail available, handle the error here echo 'No thumbnail available'; }
<?php $filename = 'test/images/test1pix.jpg'; $image = exif_thumbnail($filename, $width, $height, $type); if ($image !== false) { header('Content-type: ' . image_type_to_mime_type($type)); var_dump($width, $height, $type); } else { echo 'No thumbnail available'; }
/** * Resize this image and save the output as another File object. * * This is used on conjunction with getPreview* and getQuickPreview. * QuickPreview creates the destination file in the correct directory * and getPreview* methods request the actual resizing. * * @param Filestore\File $file The destination file * @param int $width Width of the final image (in px) * @param int $height Height of the final image (in px) * @param string $mode Mode (part of the geometry) */ private function _resizeTo(Filestore\File $file, $width, $height, $mode){ if(!$this->isImage()){ // :/ return; } \Core\Utilities\Logger\write_debug('Resizing image ' . $this->getFilename('') . ' to ' . $width . 'x' . $height . $mode); $m = $this->getMimetype(); // Make sure the directory of the destination file exists! // By touching the file, Core will create all parent directories as necessary. $file->putContents(''); if($m == 'image/gif' && exec('which convert 2>/dev/null')){ // The GIF resizer handles EVERYTHING :) // Granted of course, that imagemagick's convert is available on the server. $resize = escapeshellarg($mode . $width . 'x' . $height); exec('convert ' . escapeshellarg($this->getFilename()) . ' -resize ' . $resize . ' ' . escapeshellarg($file->getFilename())); \Core\Utilities\Logger\write_debug('Resizing complete (via convert)'); return; } // Traditional resizing logic. switch ($m) { case 'image/jpeg': $thumbType = 'JPEG'; $thumbWidth = $width; $thumbHeight = $height; if($width <= 200 && $height <= 200 && function_exists('exif_thumbnail')){ // Try to write out from the thumbnail img instead of the full size. // This is done to increase server performance. // eg: resizing a 5MB JPEG can take upwards of 50-100ms, // whereas the embedded thumbnail will take only 2-10ms. // Not to mention professional JPEG management tools such as PS and Gimp // produce marginally higher-quality thumbnails than GD will. // (The resulting filesize is negligible.) // Of course if the requested image is larger than a thumbnail size, (200x200 in this case), // using the thumbnail is counter-productive! $img = exif_thumbnail($this->getFilename(), $thumbWidth, $thumbHeight, $thumbType); if($img){ \Core\Utilities\Logger\write_debug('JPEG has thumbnail data of ' . $thumbWidth . 'x' . $thumbHeight . '!'); $file->putContents($img); $img = imagecreatefromjpeg($file->getFilename()); } else{ $img = imagecreatefromjpeg($this->getFilename()); } } else{ $img = imagecreatefromjpeg($this->getFilename()); } break; case 'image/png': $img = imagecreatefrompng($this->getFilename()); break; case 'image/gif': $img = imagecreatefromgif($this->getFilename()); break; default: // Hmmm... \Core\Utilities\Logger\write_debug('Resizing complete (failed, not sure what it was)'); return; } if ($img) { $sW = imagesx($img); $sH = imagesy($img); $nW = $sW; $nH = $sH; switch($mode){ // Standard mode, images are scaled down (only) while preserving aspect ratio case '': case '<': if ($nW > $width) { $nH = $width * $sH / $sW; $nW = $width; } if ($nH > $height) { $nW = $height * $sW / $sH; $nH = $height; } break; // Only resize up case '>': if ($nW < $width) { $nH = $width * $sH / $sW; $nW = $width; } if ($nH < $height) { $nW = $height * $sW / $sH; $nH = $height; } break; // Resize to new size, regardless about aspect ratio case '!': $nW = $width; $nH = $height; break; // Resize image based on smallest dimension case '^': $ratioheight = $sW / $height; $ratiowidth = $sH / $width; if($ratioheight > 1 && $ratiowidth > 1){ // The image is larger than any of the dimensions, I can use the reduction logic. if(($width * $sH / $sW) > ($height * $sW / $sH)){ $nH = $width * $sH / $sW; $nW = $width; } else{ $nH = $height; $nW = $height * $sW / $sH; } } elseif($ratiowidth > $ratioheight){ // The image needs to be increased in size, this logic is slightly different. $nW = $width; $nH = round($width * $sH / $sW); } else{ $nH = $height; $nW = round($height * $sW / $sH); } } // If it's a JPEG, try to find the original thumbnail. /*if(false && $m == 'image/jpeg'){ $type = 'JPEG'; $img = exif_thumbnail($this->getFilename(), $nW, $nH, $type); $file->putContents($img); return; }*/ $img2 = imagecreatetruecolor($nW, $nH); imagealphablending($img2, false); imagesavealpha($img2, true); imagealphablending($img, true); // Assign a transparency color. //$trans = imagecolorallocatealpha($img2, 0, 0, 0, 0); //imagefill($img2, 0, 0, $trans); imagecopyresampled($img2, $img, 0, 0, 0, 0, $nW, $nH, $sW, $sH); imagedestroy($img); switch ($m) { case 'image/jpeg': imagejpeg($img2, $file->getFilename(), 60); \Core\Utilities\Logger\write_debug('Resizing complete (via imagejpeg)'); break; case 'image/png': imagepng($img2, $file->getFilename(), 9); \Core\Utilities\Logger\write_debug('Resizing complete (via imagepng)'); break; case 'image/gif': imagegif($img2, $file->getFilename()); \Core\Utilities\Logger\write_debug('Resizing complete (via imagegif)'); break; default: // Hmmm... \Core\Utilities\Logger\write_debug('Resizing complete (failed, not sure what it was)'); return; } } }
<?php $file = 'beth-and-seth.jpeg'; $thumb = exif_thumbnail($file, $width, $height, $type); if ($thumb !== false) { $img = "<img src=\"{$file}\" alt=\"Beth and Seth\"\n width=\"{$width}\" height=\"{$height}\">"; print $img; }
function _streamThumb(&$man, $input) { if (!$man->verifyPath($input["path"]) < 0) { trigger_error("Path verification failed.", FATAL); die; } $path = $man->decryptPath($input["path"]); $file =& $man->getFile($path); $ext = getFileExt($file->getName()); $config = $file->getConfig(); $urlprefix = $man->toUnixPath($config['preview.urlprefix']); $urlsuffix = $man->toUnixPath($config['preview.urlsuffix']); // NOTE: Verify more stuff here before proceeding. if ($man->verifyFile($file, "thumbnail", $config) < 0) { trigger_error("Path verification failed.", FATAL); die; } //$imageutils = new $config['thumbnail']; //$canEdit = $imageutils->canEdit($ext); // Check if we have an EXIF JPG file. if ($config['thumbnail.use_exif'] == true && function_exists("exif_thumbnail") && (strtolower($ext) == "jpg" || strtolower($ext) == "jpeg")) { $image = @exif_thumbnail($file->getAbsolutePath(), $exif_width, $exif_height, $exif_type); if ($image !== false) { header('Content-type: ' . image_type_to_mime_type($exif_type)); echo $image; return null; } } $thumbnail = $this->_createThumb($man, $file); if ($thumbnail != false) { header('Content-type: ' . mapMimeTypeFromUrl($thumbnail->getName(), "../" . $config['stream.mimefile'])); if (!readfile($thumbnail->getAbsolutePath())) { header("Location: " . $urlprefix . $man->convertPathToURI($thumbnail->getAbsolutePath()) . $urlsuffix); } } else { header('Content-type: ' . mapMimeTypeFromUrl($file->getName(), "../" . $config['stream.mimefile'])); if (!readfile($file->getAbsolutePath())) { header("Location: " . $urlprefix . $man->convertPathToURI($file->getAbsolutePath()) . $urlsuffix); } } return null; }
/** * Get Thumbnail * * @return img.Image */ public function getThumbnail() { $s = new Stream(); $s->open(STREAM_MODE_WRITE); $s->write(exif_thumbnail($this->getFilename())); $s->rewind(); return Image::loadFrom(new StreamReader($s)); }
<?php $thumb = exif_thumbnail('beth-and-seth.jpeg', $width, $height, $type);
<?php var_dump(exif_thumbnail(__DIR__ . "/bug68113.jpg")); ?> Done
/** * @author Kalle Karlsson [kakar] * Returns the EXIF embedded thumbnail from JPEG and TIFF images. * The image can be resize either by width and height or percentidge. * Returns false if no thubnail is found. * @param integer $width Wanted with of the image * @param integer $height Wanted height of the image * @param bool $keepPropoertions Makes the funktion return the (proportionanly) largest possible image within the $width and $height * @param integer $percent Proportionaly resize the by a precentidge. $percent=100 means no resize ($percent > 1) * @return string|bool */ function thumbnail($width = false, $height = false, $keepProportions = true, $percent = false) { $image = exif_thumbnail($this->path, $orgWidth, $orgHeight, $type); if ($image !== false) { if ($percent > 0) { // calculate resized height and width if percent is defined $percent = $percent * 0.01; $width = $orgWidth * $percent; $height = $orgHeight * $percent; } else { if ($width && !$height) { // autocompute height if only width is set $height = 100 / ($orgWidth / $width) * 0.01; $height = @round($orgHeight * $height); } elseif ($height && !$width) { // autocompute width if only height is set $width = 100 / ($orgHeight / $height) * 0.01; $width = @round($orgWidth * $width); } elseif ($height && $width && $keepProportions) { // get the smaller resulting image dimension $hx = 100 / ($orgWidth / $width) * 0.01; $hx = @round($orgHeight * $hx); $wx = 100 / ($orgHeight / $height) * 0.01; $wx = @round($orgWidth * $wx); if ($hx < $height) { $height = 100 / ($orgWidth / $width) * 0.01; $height = @round($orgHeight * $height); } else { $width = 100 / ($orgHeight / $height) * 0.01; $width = @round($orgWidth * $width); } } } return '<img width="' . $width . '" height="' . $height . '" src="data:image/gif;base64,' . base64_encode($image) . '" />'; } else { // no thumbnail available return false; } }
/** * Creates the cache folder version of the image, including watermarking * * @param string $newfilename the name of the file when it is in the cache * @param string $imgfile the image name * @param array $args the cropping arguments * @param bool $allow_watermark set to true if image may be watermarked * @param string $theme the current theme * @param string $album the album containing the image */ function cacheImage($newfilename, $imgfile, $args, $allow_watermark = false, $theme, $album) { global $_zp_gallery; try { @(list($size, $width, $height, $cw, $ch, $cx, $cy, $quality, $thumb, $crop, $thumbstandin, $passedWM, $adminrequest, $effects) = $args); // Set the config variables for convenience. $image_use_side = getOption('image_use_side'); $upscale = getOption('image_allow_upscale'); $allowscale = true; $sharpenthumbs = getOption('thumb_sharpen'); $sharpenimages = getOption('image_sharpen'); $id = $im = NULL; $watermark_use_image = getAlbumInherited($album, 'watermark', $id); if (empty($watermark_use_image)) { $watermark_use_image = IMAGE_WATERMARK; } if (!$effects) { if ($thumb && getOption('thumb_gray')) { $effects = 'gray'; } else { if (getOption('image_gray')) { $effects = 'gray'; } } } $newfile = SERVERCACHE . $newfilename; mkdir_recursive(dirname($newfile), FOLDER_MOD); if (DEBUG_IMAGE) { debugLog("cacheImage(\$imgfile=" . basename($imgfile) . ", \$newfilename={$newfilename}, \$allow_watermark={$allow_watermark}, \$theme={$theme}) \$size={$size}, \$width={$width}, \$height={$height}, \$cw={$cw}, \$ch={$ch}, \$cx=" . (is_null($cx) ? 'NULL' : $cx) . ", \$cy=" . (is_null($cy) ? 'NULL' : $cy) . ", \$quality={$quality}, \$thumb={$thumb}, \$crop={$crop} \$image_use_side={$image_use_side}; \$upscale={$upscale});"); } // Check for the source image. if (!file_exists($imgfile) || !is_readable($imgfile)) { imageError('404 Not Found', sprintf(gettext('Image %s not found or is unreadable.'), filesystemToInternal($imgfile)), 'err-imagenotfound.png'); } $rotate = false; if (zp_imageCanRotate()) { $rotate = getImageRotation($imgfile); } $s = getSuffix($imgfile); if (function_exists('exif_thumbnail') && getOption('use_embedded_thumb') && ($s == 'jpg' || $s == 'jpeg')) { $im = exif_thumbnail($imgfile, $tw, $th, $tt); if ($im) { if ($size) { $big_enough = $tw >= $size && $th >= $size; } else { $big_enough = $tw >= $width && $th >= $height; } if ($big_enough) { $im = zp_imageFromString($im); if (DEBUG_IMAGE && $im) { debugLog(sprintf(gettext('Using %1$ux%2$u %3$s thumbnail image.'), $tw, $th, image_type_to_mime_type($tt))); } } else { $im = false; } } else { $im = false; } } if (!$im) { $im = zp_imageGet($imgfile); } if (!$im) { imageError('404 Not Found', sprintf(gettext('Image %s not renderable (imageGet).'), filesystemToInternal($imgfile)), 'err-failimage.png'); } if ($rotate) { if (DEBUG_IMAGE) { debugLog("cacheImage:rotate->{$rotate}"); } $im = zp_rotateImage($im, $rotate); if (!$im) { imageError('404 Not Found', sprintf(gettext('Image %s not rotatable.'), filesystemToInternal($imgfile)), 'err-failimage.png'); } } $w = zp_imageWidth($im); $h = zp_imageHeight($im); // Give the sizing dimension to $dim $ratio_in = ''; $ratio_out = ''; $crop = $crop || $cw != 0 || $ch != 0; if (!empty($size)) { $dim = $size; if ($crop) { $dim = $size; if (!$ch) { $ch = $size; } if (!$cw) { $cw = $size; } $width = $cw; $height = $ch; $size = false; } else { $width = $height = false; } } else { if (!empty($width) && !empty($height)) { $ratio_in = $h / $w; $ratio_out = $height / $width; if ($ratio_in > $ratio_out) { // image is taller than desired, $height is the determining factor $thumb = true; $dim = $width; if (!$ch) { $ch = $height; } } else { // image is wider than desired, $width is the determining factor $dim = $height; if (!$cw) { $cw = $width; } } } else { if (!empty($width)) { $dim = $width; $size = $height = false; } else { if (!empty($height)) { $dim = $height; $size = $width = false; } else { // There's a problem up there somewhere... imageError('404 Not Found', sprintf(gettext('Unknown error processing %s! Please report to the developers at <a href="http://www.zenphoto.org/">www.zenphoto.org</a>'), filesystemToInternal($imgfile)), 'err-imagegeneral.png'); } } } } $sizes = propSizes($size, $width, $height, $w, $h, $thumb, $image_use_side, $dim); list($neww, $newh) = $sizes; if (DEBUG_IMAGE) { debugLog("cacheImage:" . basename($imgfile) . ": \$size={$size}, \$width={$width}, \$height={$height}, \$w={$w}; \$h={$h}; \$cw={$cw}, " . "\$ch={$ch}, \$cx={$cx}, \$cy={$cy}, \$quality={$quality}, \$thumb={$thumb}, \$crop={$crop}, \$newh={$newh}, \$neww={$neww}, \$dim={$dim}, " . "\$ratio_in={$ratio_in}, \$ratio_out={$ratio_out} \$upscale={$upscale} \$rotate={$rotate} \$effects={$effects}"); } if (!$upscale && $newh >= $h && $neww >= $w) { // image is the same size or smaller than the request $neww = $w; $newh = $h; $allowscale = false; if ($crop) { if ($width > $neww) { $width = $neww; } if ($height > $newh) { $height = $newh; } } if (DEBUG_IMAGE) { debugLog("cacheImage:no upscale " . basename($imgfile) . ": \$newh={$newh}, \$neww={$neww}, \$crop={$crop}, \$thumb={$thumb}, \$rotate={$rotate}, watermark=" . $watermark_use_image); } } $watermark_image = false; if ($passedWM) { if ($passedWM != NO_WATERMARK) { $watermark_image = getWatermarkPath($passedWM); if (!file_exists($watermark_image)) { $watermark_image = SERVERPATH . '/' . ZENFOLDER . '/images/imageDefault.png'; } } } else { if ($allow_watermark) { $watermark_image = $watermark_use_image; if ($watermark_image) { if ($watermark_image != NO_WATERMARK) { $watermark_image = getWatermarkPath($watermark_image); if (!file_exists($watermark_image)) { $watermark_image = SERVERPATH . '/' . ZENFOLDER . '/images/imageDefault.png'; } } } } } // Crop the image if requested. if ($crop) { if ($cw > $ch) { $ir = $ch / $cw; } else { $ir = $cw / $ch; } if ($size) { $neww = $size; $newh = $ir * $size; } else { $neww = $width; $newh = $height; if ($neww > $newh) { if ($newh === false) { $newh = $ir * $neww; } } else { if ($neww === false) { $neww = $ir * $newh; } } } if (is_null($cx) && is_null($cy)) { // scale crop to max of image // set crop scale factor $cf = 1; if ($cw) { $cf = min($cf, $cw / $neww); } if ($ch) { $cf = min($cf, $ch / $newh); } // set the image area of the crop (use the most image possible, rule of thirds positioning) if (!$cw || $w / $cw * $ch > $h) { $cw = round($h / $ch * $cw * $cf); $ch = round($h * $cf); $cx = round(($w - $cw) / 3); } else { $ch = round($w / $cw * $ch * $cf); $cw = round($w * $cf); $cy = round(($h - $ch) / 3); } } else { // custom crop if (!$cw || $cw > $w) { $cw = $w; } if (!$ch || $ch > $h) { $ch = $h; } } // force the crop to be within the image if ($cw + $cx > $w) { $cx = $w - $cw; } if ($cx < 0) { $cw = $cw + $cx; $cx = 0; } if ($ch + $cy > $h) { $cy = $h - $ch; } if ($cy < 0) { $ch = $ch + $cy; $cy = 0; } if (DEBUG_IMAGE) { debugLog("cacheImage:crop " . basename($imgfile) . ":\$size={$size}, \$width={$width}, \$height={$height}, \$cw={$cw}, \$ch={$ch}, \$cx={$cx}, \$cy={$cy}, \$quality={$quality}, \$thumb={$thumb}, \$crop={$crop}, \$rotate={$rotate}"); } $newim = zp_createImage($neww, $newh); if (!zp_resampleImage($newim, $im, 0, 0, $cx, $cy, $neww, $newh, $cw, $ch)) { imageError('404 Not Found', sprintf(gettext('Image %s not renderable (resample).'), filesystemToInternal($imgfile)), 'err-failimage.png'); } } else { if ($newh >= $h && $neww >= $w && !$rotate && !$effects && !$watermark_image && (!$upscale || $newh == $h && $neww == $w)) { // we can just use the original! if (SYMLINK && @symlink($imgfile, $newfile)) { if (DEBUG_IMAGE) { debugLog("cacheImage:symlink original " . basename($imgfile) . ":\$size={$size}, \$width={$width}, \$height={$height}, \$dim={$dim}, \$neww={$neww}; \$newh={$newh}; \$quality={$quality}, \$thumb={$thumb}, \$crop={$crop}, \$rotate={$rotate}; \$allowscale={$allowscale};"); } clearstatcache(); return true; } else { if (@copy($imgfile, $newfile)) { if (DEBUG_IMAGE) { debugLog("cacheImage:copy original " . basename($imgfile) . ":\$size={$size}, \$width={$width}, \$height={$height}, \$dim={$dim}, \$neww={$neww}; \$newh={$newh}; \$quality={$quality}, \$thumb={$thumb}, \$crop={$crop}, \$rotate={$rotate}; \$allowscale={$allowscale};"); } clearstatcache(); return true; } } } if ($allowscale) { $sizes = propSizes($size, $width, $height, $w, $h, $thumb, $image_use_side, $dim); list($neww, $newh) = $sizes; } if (DEBUG_IMAGE) { debugLog("cacheImage:no crop " . basename($imgfile) . ":\$size={$size}, \$width={$width}, \$height={$height}, \$dim={$dim}, \$neww={$neww}; \$newh={$newh}; \$quality={$quality}, \$thumb={$thumb}, \$crop={$crop}, \$rotate={$rotate}; \$allowscale={$allowscale};"); } $newim = zp_createImage($neww, $newh); if (!zp_resampleImage($newim, $im, 0, 0, 0, 0, $neww, $newh, $w, $h)) { imageError('404 Not Found', sprintf(gettext('Image %s not renderable (resample).'), filesystemToInternal($imgfile)), 'err-failimage.png'); } if ($thumb && $sharpenthumbs || !$thumb && $sharpenimages) { if (!zp_imageUnsharpMask($newim, getOption('sharpen_amount'), getOption('sharpen_radius'), getOption('sharpen_threshold'))) { imageError('404 Not Found', sprintf(gettext('Image %s not renderable (unsharp).'), filesystemToInternal($imgfile)), 'err-failimage.png'); } } } $imgEffects = explode(',', $effects); if (in_array('gray', $imgEffects)) { zp_imageGray($newim); } if ($watermark_image) { $offset_h = getOption('watermark_h_offset') / 100; $offset_w = getOption('watermark_w_offset') / 100; $percent = getOption('watermark_scale') / 100; $watermark = zp_imageGet($watermark_image); if (!$watermark) { imageError('404 Not Found', sprintf(gettext('Watermark %s not renderable.'), $watermark_image), 'err-failimage.png'); } $watermark_width = zp_imageWidth($watermark); $watermark_height = zp_imageHeight($watermark); $imw = zp_imageWidth($newim); $imh = zp_imageHeight($newim); $nw = sqrt($imw * $imh * $percent * ($watermark_width / $watermark_height)); $nh = $nw * ($watermark_height / $watermark_width); $r = sqrt($imw * $imh * $percent / ($watermark_width * $watermark_height)); if (!getOption('watermark_allow_upscale')) { $r = min(1, $r); } $nw = round($watermark_width * $r); $nh = round($watermark_height * $r); if ($nw != $watermark_width || $nh != $watermark_height) { $watermark = zp_imageResizeAlpha($watermark, $nw, $nh); if (!$watermark) { imageError('404 Not Found', sprintf(gettext('Watermark %s not resizeable.'), $watermark_image), 'err-failimage.png'); } } // Position Overlay in Bottom Right $dest_x = max(0, floor(($imw - $nw) * $offset_w)); $dest_y = max(0, floor(($imh - $nh) * $offset_h)); if (DEBUG_IMAGE) { debugLog("Watermark:" . basename($imgfile) . ": \$offset_h={$offset_h}, \$offset_w={$offset_w}, \$watermark_height={$watermark_height}, \$watermark_width={$watermark_width}, \$imw={$imw}, \$imh={$imh}, \$percent={$percent}, \$r={$r}, \$nw={$nw}, \$nh={$nh}, \$dest_x={$dest_x}, \$dest_y={$dest_y}"); } if (!zp_copyCanvas($newim, $watermark, $dest_x, $dest_y, 0, 0, $nw, $nh)) { imageError('404 Not Found', sprintf(gettext('Image %s not renderable (copycanvas).'), filesystemToInternal($imgfile)), 'err-failimage.png'); } zp_imageKill($watermark); } // Create the cached file (with lots of compatibility)... @chmod($newfile, 0777); if (zp_imageOutput($newim, getSuffix($newfile), $newfile, $quality)) { // successful save of cached image if (getOption('ImbedIPTC') && getSuffix($newfilename) == 'jpg' && GRAPHICS_LIBRARY != 'Imagick') { // the imbed function works only with JPEG images global $_zp_extra_filetypes; // because we are doing the require in a function! if (!$_zp_extra_filetypes) { $_zp_extra_filetypes = array(); } require_once dirname(__FILE__) . '/functions.php'; // it is ok to increase memory footprint now since the image processing is complete $iptc = array('1#090' => chr(0x1b) . chr(0x25) . chr(0x47), '2#115' => $_zp_gallery->getTitle()); $iptc_data = zp_imageIPTC($imgfile); if ($iptc_data) { $iptc_data = iptcparse($iptc_data); if ($iptc_data) { $iptc = array_merge($iptc_data, $iptc); } } $imgfile = str_replace(ALBUM_FOLDER_SERVERPATH, '', $imgfile); $imagename = basename($imgfile); $albumname = dirname($imgfile); $image = newImage(newAlbum($albumname), $imagename); $copyright = $image->getCopyright(); if (empty($copyright)) { $copyright = getOption('default_copyright'); } if (!empty($copyright)) { $iptc['2#116'] = $copyright; } $credit = $image->getCredit(); if (!empty($credit)) { $iptc['2#110'] = $credit; } $iptc_result = ''; foreach ($iptc as $tag => $string) { $tag_parts = explode('#', $tag); if (is_array($string)) { foreach ($string as $element) { $iptc_result .= iptc_make_tag($tag_parts[0], $tag_parts[1], $element); } } else { $iptc_result .= iptc_make_tag($tag_parts[0], $tag_parts[1], $string); } } $content = iptcembed($iptc_result, $newfile); $fw = fopen($newfile, 'w'); fwrite($fw, $content); fclose($fw); clearstatcache(); } @chmod($newfile, FILE_MOD); if (DEBUG_IMAGE) { debugLog('Finished:' . basename($imgfile)); } } else { if (DEBUG_IMAGE) { debugLog('cacheImage: failed to create ' . $newfile); } imageError('404 Not Found', sprintf(gettext('cacheImage: failed to create %s'), $newfile), 'err-failimage.png'); } @chmod($newfile, FILE_MOD); zp_imageKill($newim); zp_imageKill($im); } catch (Exception $e) { debugLog('cacheImage(' . $newfilename . ') exception: ' . $e->getMessage()); imageError('404 Not Found', sprintf(gettext('cacheImage(%1$s) exception: %2$s'), $newfilename, $e->getMessage()), 'err-failimage.png'); return false; } clearstatcache(); return true; }
<?php $image = exif_thumbnail($_GET["path"]); //php's implementation Header("Content-type: image/jpeg"); echo $image;
/** * Creates a thumbnail for the specified file and returns that file object * or the input file if thumbnails are disabled or not supported. * * @param MOXMAN_Vfs_IFile $file File to generate thumbnail for. * @return MOXMAN_Vfs_IFile File instance that got generated or input file. */ public function createThumbnail(MOXMAN_Vfs_IFile $file, $localTempFile = null) { $config = $file->getConfig(); // Thumbnails disabled in config if (!$config->get('thumbnail.enabled')) { return $file; } // File is not an image if (!MOXMAN_Media_ImageAlter::canEdit($file)) { return $file; } // No write access to parent path $dirFile = $file->getParentFile(); if (!$dirFile->canWrite()) { return $file; } $thumbnailFolderPath = MOXMAN_Util_PathUtils::combine($file->getParent(), $config->get('thumbnail.folder')); $thumbnailFile = MOXMAN::getFile($thumbnailFolderPath, $config->get('thumbnail.prefix') . $file->getName()); // Never generate thumbs in thumbs dirs if (basename($file->getParent()) == $config->get('thumbnail.folder')) { return $file; } $thumbnailFolderFile = $thumbnailFile->getParentFile(); if ($thumbnailFile->exists()) { if ($file->isDirectory()) { return $file; } return $thumbnailFile; } if (!$thumbnailFolderFile->exists()) { $thumbnailFolderFile->mkdir(); $this->fireThumbnailFileAction(MOXMAN_Vfs_FileActionEventArgs::ADD, $thumbnailFolderFile); } // TODO: Maybe implement this inside MOXMAN_Media_ImageAlter if ($file instanceof MOXMAN_Vfs_Local_File) { if ($config->get('thumbnail.use_exif') && function_exists("exif_thumbnail") && preg_match('/jpe?g/i', MOXMAN_Util_PathUtils::getExtension($file->getName()))) { $imageType = null; $width = 0; $height = 0; try { // Silently fail this, hence the @, some exif data can be corrupt. $exifImage = @exif_thumbnail($localTempFile ? $localTempFile : $file->getInternalPath(), $width, $height, $imageType); if ($exifImage) { $stream = $thumbnailFile->open(MOXMAN_Vfs_IFileStream::WRITE); $stream->write($exifImage); $stream->close(); $this->fireThumbnailFileAction(MOXMAN_Vfs_FileActionEventArgs::ADD, $thumbnailFile); return $thumbnailFile; } } catch (Exception $e) { // Ignore exif failure } } } $imageAlter = new MOXMAN_Media_ImageAlter(); if ($localTempFile) { $imageAlter->load($localTempFile); } else { $imageAlter->loadFromFile($file); } $imageAlter->createThumbnail($config->get('thumbnail.width'), $config->get('thumbnail.height'), $config->get('thumbnail.mode', "resize")); $imageAlter->saveToFile($thumbnailFile, $config->get('thumbnail.jpeg_quality')); $this->fireThumbnailFileAction(MOXMAN_Vfs_FileActionEventArgs::ADD, $thumbnailFile); return $thumbnailFile; }
function ExtractEXIFgetImageSize() { $this->DebugMessage('starting ExtractEXIFgetImageSize()', __FILE__, __LINE__); if (preg_match('#^http:#i', $this->src) && !$this->sourceFilename && $this->rawImageData) { !$this->SourceDataToTempFile(); } if (is_null($this->getimagesizeinfo)) { if ($this->sourceFilename) { $this->getimagesizeinfo = @GetImageSize($this->sourceFilename); $this->source_width = $this->getimagesizeinfo[0]; $this->source_height = $this->getimagesizeinfo[1]; $this->DebugMessage('GetImageSize(' . $this->sourceFilename . ') says image is ' . $this->source_width . 'x' . $this->source_height, __FILE__, __LINE__); } else { $this->DebugMessage('skipping GetImageSize() because $this->sourceFilename is empty', __FILE__, __LINE__); } } else { $this->DebugMessage('skipping GetImageSize() because !is_null($this->getimagesizeinfo)', __FILE__, __LINE__); } if (is_resource($this->gdimg_source)) { $this->source_width = ImageSX($this->gdimg_source); $this->source_height = ImageSY($this->gdimg_source); $this->SetOrientationDependantWidthHeight(); } elseif ($this->rawImageData && !$this->sourceFilename) { if ($this->SourceImageIsTooLarge($this->source_width, $this->source_height)) { $this->DebugMessage('NOT bypassing EXIF and GetImageSize sections because source image is too large for GD (' . $this->source_width . 'x' . $this->source_width . '=' . $this->source_width * $this->source_height * 5 . 'MB)', __FILE__, __LINE__); } else { $this->DebugMessage('bypassing EXIF and GetImageSize sections because $this->rawImageData is set, and $this->sourceFilename is not set, and source image is not too large for GD (' . $this->source_width . 'x' . $this->source_width . '=' . $this->source_width * $this->source_height * 5 . 'MB)', __FILE__, __LINE__); } } if (is_null($this->getimagesizeinfo)) { $this->getimagesizeinfo = @GetImageSize($this->sourceFilename); } if (!empty($this->getimagesizeinfo)) { // great $this->getimagesizeinfo['filesize'] = @filesize($this->sourceFilename); } elseif (!$this->rawImageData) { $this->DebugMessage('GetImageSize("' . $this->sourceFilename . '") failed', __FILE__, __LINE__); } if ($this->config_prefer_imagemagick) { if ($this->ImageMagickThumbnailToGD()) { return true; } $this->DebugMessage('ImageMagickThumbnailToGD() failed', __FILE__, __LINE__); } $this->source_width = $this->getimagesizeinfo[0]; $this->source_height = $this->getimagesizeinfo[1]; $this->SetOrientationDependantWidthHeight(); if (phpthumb_functions::version_compare_replacement(phpversion(), '4.2.0', '>=') && function_exists('exif_read_data')) { switch ($this->getimagesizeinfo[2]) { case IMAGETYPE_JPEG: case IMAGETYPE_TIFF_II: case IMAGETYPE_TIFF_MM: $this->exif_raw_data = @exif_read_data($this->sourceFilename, 0, true); break; } } if (function_exists('exif_thumbnail') && $this->getimagesizeinfo[2] == IMAGETYPE_JPEG) { // Extract EXIF info from JPEGs $this->exif_thumbnail_width = ''; $this->exif_thumbnail_height = ''; $this->exif_thumbnail_type = ''; // The parameters width, height and imagetype are available since PHP v4.3.0 if (phpthumb_functions::version_compare_replacement(phpversion(), '4.3.0', '>=')) { $this->exif_thumbnail_data = @exif_thumbnail($this->sourceFilename, $this->exif_thumbnail_width, $this->exif_thumbnail_height, $this->exif_thumbnail_type); } else { // older versions of exif_thumbnail output an error message but NOT return false on failure ob_start(); $this->exif_thumbnail_data = exif_thumbnail($this->sourceFilename); $exit_thumbnail_error = ob_get_contents(); ob_end_clean(); if (!$exit_thumbnail_error && $this->exif_thumbnail_data) { if ($gdimg_exif_temp = $this->ImageCreateFromStringReplacement($this->exif_thumbnail_data, false)) { $this->exif_thumbnail_width = ImageSX($gdimg_exif_temp); $this->exif_thumbnail_height = ImageSY($gdimg_exif_temp); $this->exif_thumbnail_type = 2; // (2 == JPEG) before PHP v4.3.0 only JPEG format EXIF thumbnails are returned unset($gdimg_exif_temp); } else { return $this->ErrorImage('Failed - $this->ImageCreateFromStringReplacement($this->exif_thumbnail_data) in ' . __FILE__ . ' on line ' . __LINE__); } } } } elseif (!function_exists('exif_thumbnail')) { $this->DebugMessage('exif_thumbnail() does not exist, cannot extract EXIF thumbnail', __FILE__, __LINE__); } $this->DebugMessage('EXIF thumbnail extraction: (size=' . strlen($this->exif_thumbnail_data) . '; type="' . $this->exif_thumbnail_type . '"; ' . intval($this->exif_thumbnail_width) . 'x' . intval($this->exif_thumbnail_height) . ')', __FILE__, __LINE__); // see if EXIF thumbnail can be used directly with no processing if ($this->config_use_exif_thumbnail_for_speed && $this->exif_thumbnail_data) { while (true) { if (!$this->xto) { $source_ar = $this->source_width / $this->source_height; $exif_ar = $this->exif_thumbnail_width / $this->exif_thumbnail_height; if (number_format($source_ar, 2) != number_format($exif_ar, 2)) { $this->DebugMessage('not using EXIF thumbnail because $source_ar != $exif_ar (' . $source_ar . ' != ' . $exif_ar . ')', __FILE__, __LINE__); break; } if ($this->w && $this->w != $this->exif_thumbnail_width) { $this->DebugMessage('not using EXIF thumbnail because $this->w != $this->exif_thumbnail_width (' . $this->w . ' != ' . $this->exif_thumbnail_width . ')', __FILE__, __LINE__); break; } if ($this->h && $this->h != $this->exif_thumbnail_height) { $this->DebugMessage('not using EXIF thumbnail because $this->h != $this->exif_thumbnail_height (' . $this->h . ' != ' . $this->exif_thumbnail_height . ')', __FILE__, __LINE__); break; } $CannotBeSetParameters = array('sx', 'sy', 'sh', 'sw', 'far', 'bg', 'bc', 'fltr', 'phpThumbDebug'); foreach ($CannotBeSetParameters as $parameter) { if ($this->{$parameter}) { break 2; } } } $this->DebugMessage('setting $this->gdimg_source = $this->ImageCreateFromStringReplacement($this->exif_thumbnail_data)', __FILE__, __LINE__); $this->gdimg_source = $this->ImageCreateFromStringReplacement($this->exif_thumbnail_data); $this->source_width = ImageSX($this->gdimg_source); $this->source_height = ImageSY($this->gdimg_source); return true; } } if ($this->config_max_source_pixels > 0 && $this->source_width * $this->source_height > $this->config_max_source_pixels) { // Source image is larger than would fit in available PHP memory. // If ImageMagick is installed, use it to generate the thumbnail. // Else, if an EXIF thumbnail is available, use that as the source image. // Otherwise, no choice but to fail with an error message $this->DebugMessage('image is ' . $this->source_width . 'x' . $this->source_height . ' and therefore contains more pixels (' . $this->source_width * $this->source_height . ') than $this->config_max_source_pixels setting (' . $this->config_max_source_pixels . ')', __FILE__, __LINE__); if (!$this->config_prefer_imagemagick && $this->ImageMagickThumbnailToGD()) { // excellent, we have a thumbnailed source image return true; } } return true; }
// get some information about the image $path = getRequestParam("path", ""); $width = getRequestParam("width", ""); $height = getRequestParam("height", ""); $ext = getRequestParam("ext", ""); $th_folder = ""; verifyAccess($mcImageManagerConfig); $rootpath = removeTrailingSlash(getRequestParam("rootpath", toUnixPath(getRealPath($mcImageManagerConfig, 'filesystem.rootpath')))); $fileFactory =& new FileFactory($mcImageManagerConfig, $rootPath); $file =& $fileFactory->getFile($path); $config = $file->getConfig(); $imageutils = new $config['thumbnail'](); $canEdit = $imageutils->_canEdit; $proceed = true; if ($config['thumbnail.use_exif'] == true and exifExists()) { $image = @exif_thumbnail($file->getAbsolutePath(), $exif_width, $exif_height, $exif_type); if ($image !== false) { header('Content-type: ' . image_type_to_mime_type($exif_type)); echo $image; die; } } // Preview path $wwwroot = removeTrailingSlash(toUnixPath(getWWWRoot($config))); $urlprefix = removeTrailingSlash(toUnixPath($config['preview.urlprefix'])); $urlsuffix = toUnixPath($config['preview.urlsuffix']); $pos = strpos($path, $wwwroot); if ($pos !== false && $pos == 0) { $previewurl = $urlprefix . substr($path, strlen($wwwroot)); } else { $previewurl = "";
private function createCacheThumb($file) { jimport('joomla.filesystem.file'); $browser = $this->getBrowser(); $editor = $this->getImageEditor(); // check path WFUtility::checkPath($file); $file = WFUtility::makePath($browser->getBaseDir(), $file); // default for list thumbnails $width = 100; $height = 100; $quality = 75; $data = @getimagesize($file); $mime = $data['mime']; if ($data[0] < $width && $data[1] < $height) { return $this->outputImage($file, $mime); } // try exif thumbnail if ($mime == 'image/jpeg' || $mime == 'image/tiff') { $exif = exif_thumbnail($file, $width, $height, $type); if ($exif !== false) { header("Content-type: " . image_type_to_mime_type($type)); die($exif); } } $thumb = $this->getCacheThumbPath($file, $width, $height); if (JFile::exists($thumb)) { return $this->outputImage($thumb, $mime); } $coords = $this->cropThumbnail($data[0], $data[1], $width, $height); if (self::checkMem($data)) { if ($editor->resize($file, $thumb, $width, $height, $quality, $coords['sx'], $coords['sy'], $coords['sw'], $coords['sh'])) { if (JFile::exists($thumb)) { return $this->outputImage($thumb, $mime); } } } // exit with no data exit; }
function ExtractEXIFgetImageSize() { if (is_resource($this->gdimg_source)) { $this->source_width = ImageSX($this->gdimg_source); $this->source_height = ImageSY($this->gdimg_source); } elseif ($this->rawImageData && !$this->sourceFilename) { $this->DebugMessage('bypassing EXIF and GetImageSize sections because $this->rawImageData is set and $this->sourceFilename is not', __FILE__, __LINE__); } elseif ($this->getimagesizeinfo = @GetImageSize($this->sourceFilename)) { $this->source_width = $this->getimagesizeinfo[0]; $this->source_height = $this->getimagesizeinfo[1]; if (function_exists('exif_thumbnail') && $this->getimagesizeinfo[2] == 2) { // Extract EXIF info from JPEGs $this->exif_thumbnail_width = ''; $this->exif_thumbnail_height = ''; $this->exif_thumbnail_type = ''; // The parameters width, height and imagetype are available since PHP v4.3.0 if (phpthumb_functions::version_compare_replacement(phpversion(), '4.3.0', '>=')) { $this->exif_thumbnail_data = @exif_thumbnail($this->sourceFilename, $this->exif_thumbnail_width, $this->exif_thumbnail_height, $this->exif_thumbnail_type); } else { // older versions of exif_thumbnail output an error message but NOT return false on failure ob_start(); $this->exif_thumbnail_data = exif_thumbnail($this->sourceFilename); $exit_thumbnail_error = ob_get_contents(); ob_end_clean(); if (empty($exit_thumbnail_error) && !empty($this->exif_thumbnail_data)) { if ($gdimg_exif_temp = $this->ImageCreateFromStringReplacement($this->exif_thumbnail_data, false)) { $this->exif_thumbnail_width = ImageSX($gdimg_exif_temp); $this->exif_thumbnail_height = ImageSY($gdimg_exif_temp); $this->exif_thumbnail_type = 2; // (2 == JPEG) before PHP v4.3.0 only JPEG format EXIF thumbnails are returned unset($gdimg_exif_temp); } else { return $this->ErrorImage('Failed - $this->ImageCreateFromStringReplacement($this->exif_thumbnail_data) in ' . __FILE__ . ' on line ' . __LINE__); } } } } elseif (!function_exists('exif_thumbnail')) { $this->DebugMessage('exif_thumbnail() does not exist, cannot extract EXIF thumbnail', __FILE__, __LINE__); } // see if EXIF thumbnail can be used directly with no processing if (!empty($this->exif_thumbnail_data)) { while (true) { if (empty($this->xto)) { if (isset($this->w) && $this->w != $this->exif_thumbnail_width) { break; } if (isset($this->h) && $this->h != $this->exif_thumbnail_height) { break; } $CannotBeSetParameters = array('sx', 'sy', 'sh', 'sw', 'far', 'bg', 'bc', 'fltr', 'phpThumbDebug'); foreach ($CannotBeSetParameters as $parameter) { if (!empty($this->{$parameter})) { break 2; } } } // EXIF thumbnail can be used directly for these parameters - write cached file $ImageTypesLookup = array(2 => 'jpeg'); // EXIF thumbnails are (currently?) only availble from JPEG source images if (is_dir($this->config_cache_directory) && is_writable($this->config_cache_directory) && isset($ImageTypesLookup[$this->exif_thumbnail_type])) { if ($fp_cached = @fopen($this->cache_filename, 'wb')) { fwrite($fp_cached, $this->exif_thumbnail_data); fclose($fp_cached); } else { $this->DebugMessage('failed to fopen $this->cache_filename (' . $this->cache_filename . ')', __FILE__, __LINE__); } } else { $this->DebugMessage('!is_dir($this->config_cache_directory), or !is_writable($this->config_cache_directory) (' . $this->cache_filename . '); or !isset($ImageTypesLookup[' . $this->exif_thumbnail_type . '])', __FILE__, __LINE__); } if ($mime_type = phpthumb_functions::ImageTypeToMIMEtype($this->exif_thumbnail_type)) { header('Content-type: ' . $mime_type); echo $this->exif_thumbnail_data; exit; } else { return $this->ErrorImage('phpthumb_functions::ImageTypeToMIMEtype(' . $this->exif_thumbnail_type . ') failed in ' . __FILE__ . ' on line ' . __LINE__); } break; } } if ($this->config_max_source_pixels > 0 && $this->source_width * $this->source_height > $this->config_max_source_pixels) { // Source image is larger than would fit in available PHP memory. // If ImageMagick is installed, use it to generate the thumbnail. // Else, if an EXIF thumbnail is available, use that as the source image. // Otherwise, no choice but to fail with an error message $this->DebugMessage('image is ' . $this->source_width . 'x' . $this->source_height . ' and therefore contains more pixels (' . $this->source_width * $this->source_height . ') than $this->config_max_source_pixels setting (' . $this->config_max_source_pixels . ')', __FILE__, __LINE__); if ($this->ImageMagickThumbnailToGD()) { // excellent, we have a thumbnailed source image } elseif (!empty($this->exif_thumbnail_data)) { $this->DebugMessage('ImageMagickThumbnailToGD() failed, but $this->exif_thumbnail_data is usable', __FILE__, __LINE__); // EXIF thumbnail exists, and will be use as source image $this->gdimg_source = $this->ImageCreateFromStringReplacement($this->exif_thumbnail_data); $this->source_width = $this->exif_thumbnail_width; $this->source_height = $this->exif_thumbnail_height; // override allow-enlarging setting if EXIF thumbnail is the only source available // otherwise thumbnails larger than the EXIF thumbnail will be created at EXIF size $this->config_output_allow_enlarging = true; } else { return $this->ErrorImage('Source image is (' . $this->source_width . 'x' . $this->source_height . ') which equals ' . sprintf('%1.1f', $this->source_width * $this->source_height) . ' megapixels, which is more than the allowed ' . sprintf('%1.1f', $this->config_max_source_pixels / 1000000) . ' megapixels -- insufficient memory.' . "\n" . 'EXIF thumbnail unavailable.'); } } } else { $this->DebugMessage('GetImageSize("' . $this->sourceFilename . '") failed', __FILE__, __LINE__); } return true; }
function save_thumbnail($thumb_img_url) { // create and save thumbnail // save thumbnail $imageServerPath = $_SERVER['DOCUMENT_ROOT'] . '/web_test/image_test/upload_image/'; $thumbServerPath = $_SERVER['DOCUMENT_ROOT'] . '/web_test/image_test/thumbnails/'; $defaultImagePath = $_SERVER['DOCUMENT_ROOT'] . '/web_test/image_test/'; $imageName; if (isset($thumb_img_url)) { $imageName = $thumb_img_url; } else { $imageName = 'default_backdrop_img.jpg'; if (!is_dir($imageServerPath)) { @mkdir($imageServerPath); } // copy default image file if (!file_exists($imageServerPath . $imageName)) { // file check if (!copy($defaultImagePath . $imageName, $imageServerPath . $imageName)) { // copy echo "<center>default image file copy error</center>"; // fail } else { if (file_exists($imageServerPath . $imageName)) { // success } } } } if (!is_dir($thumbServerPath)) { @mkdir($thumbServerPath); } $exif_data = exif_read_data($imageServerPath . $imageName, 0, true); $exist_thumbnail = false; foreach ($exif_data as $key => $section) { if (in_array("THUMBNAIL", $section)) { $exist_thumbnail = true; break; } } if ($exist_thumbnail) { $thumbData = exif_thumbnail($thumbServerPath . $imageName, $thumb_width, $thumb_height, $thumb_type); $thumb = imagecreatefromstring($thumbData); } else { $thumb_width = 200; $thumb_height = 200; $thumb = resize_image($imageServerPath . $imageName, 200, 200); } if (!is_dir($thumbServerPath)) { @mkdir($thumbServerPath); } if (imagejpeg($thumb, $thumbServerPath . $imageName, 100)) { } else { // 실패시 db에 저장했던 내용 취소를 위한 롤백 echo "thumbnail 실패"; exit; } // if return $imageName; }
function ReadSourceExif($image_file_name) { $this->DestroyImage(); $image_stats = @getimagesize($image_file_name); if ($image_stats[2] != IMG_JPG) { return false; } $this->ImageID = imagecreatefromstring(exif_thumbnail($image_file_name, $width, $height, $type)); $this->ExifData = @exif_read_data($image_file_name, 0, true); if ($this->ImageTypeNo != IMG_JPG || !$this->ImageID) { return false; } $this->ChangeFlag = true; return true; }