function spit_phpthumb_image($filepath, $configarray = array()) { // set up class global $CFG, $PHPTHUMB_CONFIG; $phpThumb = new phpThumb(); // import default config if (!empty($PHPTHUMB_CONFIG)) { foreach ($PHPTHUMB_CONFIG as $key => $value) { $keyname = 'config_' . $key; $phpThumb->setParameter($keyname, $value); } } // import passed params if (!empty($configarray)) { foreach ($configarray as $key => $value) { $keyname = $key; $phpThumb->setParameter($keyname, $value); } } $phpThumb->setSourceFilename($filepath); if (!is_file($phpThumb->sourceFilename) && !phpthumb_functions::gd_version()) { if (!headers_sent()) { // base64-encoded error image in GIF format $ERROR_NOGD = 'R0lGODlhIAAgALMAAAAAABQUFCQkJDY2NkZGRldXV2ZmZnJycoaGhpSUlKWlpbe3t8XFxdXV1eTk5P7+/iwAAAAAIAAgAAAE/vDJSau9WILtTAACUinDNijZtAHfCojS4W5H+qxD8xibIDE9h0OwWaRWDIljJSkUJYsN4bihMB8th3IToAKs1VtYM75cyV8sZ8vygtOE5yMKmGbO4jRdICQCjHdlZzwzNW4qZSQmKDaNjhUMBX4BBAlmMywFSRWEmAI6b5gAlhNxokGhooAIK5o/pi9vEw4Lfj4OLTAUpj6IabMtCwlSFw0DCKBoFqwAB04AjI54PyZ+yY3TD0ss2YcVmN/gvpcu4TOyFivWqYJlbAHPpOntvxNAACcmGHjZzAZqzSzcq5fNjxFmAFw9iFRunD1epU6tsIPmFCAJnWYE0FURk7wJDA0MTKpEzoWAAskiAAA7'; header('Content-Type: image/gif'); echo base64_decode($ERROR_NOGD); } else { echo '*** ERROR: No PHP-GD support available ***'; } exit; } $phpThumb->SetCacheFilename(); if (!file_exists($phpThumb->cache_filename) && is_writable(dirname($phpThumb->cache_filename))) { // error_log("generating to cache: " . $phpThumb->cache_filename); $phpThumb->CleanUpCacheDirectory(); $phpThumb->GenerateThumbnail(); $phpThumb->RenderToFile($phpThumb->cache_filename); } if (is_file($phpThumb->cache_filename)) { // error_log("sending from cache: " . $phpThumb->cache_filename); if ($getimagesize = @GetImageSize($phpThumb->cache_filename)) { $mimetype = phpthumb_functions::ImageTypeToMIMEtype($getimagesize[2]); } spitfile_with_mtime_check($phpThumb->cache_filename, $mimetype); } else { // error_log("phpthumb cache file doesn't exist: " . $phpThumb->cache_filename); $phpThumb->GenerateThumbnail(); $phpThumb->OutputThumbnail(); exit; } }
if (!(include_once '../phpthumb.class.php')) { //ob_end_flush(); die('failed to include_once("../phpthumb.class.php")'); } //ob_end_clean(); $phpThumb = new phpThumb(); if (include_once '../phpThumb.config.php') { foreach ($PHPTHUMB_CONFIG as $key => $value) { $keyname = 'config_' . $key; $phpThumb->setParameter($keyname, $value); } } $ServerInfo['phpthumb_version'] = $phpThumb->phpthumb_version; $ServerInfo['im_version'] = $phpThumb->ImageMagickVersion(); $ServerInfo['gd_string'] = phpthumb_functions::gd_version(true); $ServerInfo['gd_numeric'] = phpthumb_functions::gd_version(false); unset($phpThumb); ?> <html> <head> <title>Demo of phpThumb() - thumbnails created by PHP using GD and/or ImageMagick</title> <link rel="stylesheet" type="text/css" href="/style.css" title="style sheet"> </head> <body bgcolor="#C5C5C5"> This is a demo of <a href="http://phpthumb.sourceforge.net"><b>phpThumb()</b></a> (current version: v<?php echo @$ServerInfo['phpthumb_version']; ?> )<br> <a href="index.php?list=1">Other phpThumb() demos</a> are also available.<br>
public static function ImprovedImageRotate(&$gdimg_source, $rotate_angle = 0, $config_background_hexcolor = 'FFFFFF', $bg = null, &$phpThumbObject) { while ($rotate_angle < 0) { $rotate_angle += 360; } $rotate_angle = $rotate_angle % 360; if ($rotate_angle != 0) { $background_color = phpthumb_functions::ImageHexColorAllocate($gdimg_source, $config_background_hexcolor); if (phpthumb_functions::gd_version() >= 2 && !$bg && $rotate_angle % 90) { //$this->DebugMessage('Using alpha rotate', __FILE__, __LINE__); if ($gdimg_rotate_mask = phpthumb_functions::ImageCreateFunction(ImageSX($gdimg_source), ImageSY($gdimg_source))) { for ($i = 0; $i <= 255; $i++) { $color_mask[$i] = ImageColorAllocate($gdimg_rotate_mask, $i, $i, $i); } ImageFilledRectangle($gdimg_rotate_mask, 0, 0, ImageSX($gdimg_rotate_mask), ImageSY($gdimg_rotate_mask), $color_mask[255]); $imageX = ImageSX($gdimg_source); $imageY = ImageSY($gdimg_source); for ($x = 0; $x < $imageX; $x++) { for ($y = 0; $y < $imageY; $y++) { $pixelcolor = phpthumb_functions::GetPixelColor($gdimg_source, $x, $y); ImageSetPixel($gdimg_rotate_mask, $x, $y, $color_mask[255 - round($pixelcolor['alpha'] * 255 / 127)]); } } $gdimg_rotate_mask = ImageRotate($gdimg_rotate_mask, $rotate_angle, $color_mask[0]); $gdimg_source = ImageRotate($gdimg_source, $rotate_angle, $background_color); ImageAlphaBlending($gdimg_source, false); ImageSaveAlpha($gdimg_source, true); //$this->is_alpha = true; $phpThumbFilters = new phpthumb_filters(); //$phpThumbFilters->phpThumbObject = $this; $phpThumbFilters->phpThumbObject = $phpThumbObject; $phpThumbFilters->ApplyMask($gdimg_rotate_mask, $gdimg_source); ImageDestroy($gdimg_rotate_mask); } else { //$this->DebugMessage('ImageCreateFunction() failed', __FILE__, __LINE__); } } else { if (phpthumb_functions::gd_version() < 2) { //$this->DebugMessage('Using non-alpha rotate because gd_version is "'.phpthumb_functions::gd_version().'"', __FILE__, __LINE__); } elseif ($bg) { //$this->DebugMessage('Using non-alpha rotate because $this->bg is "'.$bg.'"', __FILE__, __LINE__); } elseif ($rotate_angle % 90) { //$this->DebugMessage('Using non-alpha rotate because ($rotate_angle % 90) = "'.($rotate_angle % 90).'"', __FILE__, __LINE__); } else { //$this->DebugMessage('Using non-alpha rotate because $this->thumbnailFormat is "'.$this->thumbnailFormat.'"', __FILE__, __LINE__); } if (ImageColorTransparent($gdimg_source) >= 0) { // ImageRotate() forgets all about an image's transparency and sets the transparent color to black // To compensate, flood-fill the transparent color of the source image with the specified background color first // then rotate and the colors should match if (!function_exists('ImageIsTrueColor') || !ImageIsTrueColor($gdimg_source)) { // convert paletted image to true-color before rotating to prevent nasty aliasing artifacts //$this->source_width = ImageSX($gdimg_source); //$this->source_height = ImageSY($gdimg_source); $gdimg_newsrc = phpthumb_functions::ImageCreateFunction(ImageSX($gdimg_source), ImageSY($gdimg_source)); $background_color = phpthumb_functions::ImageHexColorAllocate($gdimg_newsrc, $config_background_hexcolor); ImageFilledRectangle($gdimg_newsrc, 0, 0, ImageSX($gdimg_source), ImageSY($gdimg_source), phpthumb_functions::ImageHexColorAllocate($gdimg_newsrc, $config_background_hexcolor)); ImageCopy($gdimg_newsrc, $gdimg_source, 0, 0, 0, 0, ImageSX($gdimg_source), ImageSY($gdimg_source)); ImageDestroy($gdimg_source); unset($gdimg_source); $gdimg_source = $gdimg_newsrc; unset($gdimg_newsrc); } else { ImageColorSet($gdimg_source, ImageColorTransparent($gdimg_source), hexdec(substr($config_background_hexcolor, 0, 2)), hexdec(substr($config_background_hexcolor, 2, 2)), hexdec(substr($config_background_hexcolor, 4, 2))); ImageColorTransparent($gdimg_source, -1); } } $gdimg_source = ImageRotate($gdimg_source, $rotate_angle, $background_color); } } return true; }
function ImageCreateFunction($x_size, $y_size) { $ImageCreateFunction = 'ImageCreate'; if (phpthumb_functions::gd_version() >= 2.0) { $ImageCreateFunction = 'ImageCreateTrueColor'; } if (!function_exists($ImageCreateFunction)) { return phpthumb::ErrorImage($ImageCreateFunction . '() does not exist - no GD support?'); } if ($x_size <= 0 || $y_size <= 0) { return phpthumb::ErrorImage('Invalid image dimensions: ' . $ImageCreateFunction . '(' . $x_size . ', ' . $y_size . ')'); } return $ImageCreateFunction(round($x_size), round($y_size)); }
function ImageResizeFunction(&$dst_im, &$src_im, $dstX, $dstY, $srcX, $srcY, $dstW, $dstH, $srcW, $srcH) { $this->DebugMessage('ImageResizeFunction($o, $s, ' . $dstX . ', ' . $dstY . ', ' . $srcX . ', ' . $srcY . ', ' . $dstW . ', ' . $dstH . ', ' . $srcW . ', ' . $srcH . ')', __FILE__, __LINE__); if ($dstW == $srcW && $dstH == $srcH) { return ImageCopy($dst_im, $src_im, $dstX, $dstY, $srcX, $srcY, $srcW, $srcH); } if (phpthumb_functions::gd_version() >= 2.0) { if ($this->config_disable_imagecopyresampled) { return phpthumb_functions::ImageCopyResampleBicubic($dst_im, $src_im, $dstX, $dstY, $srcX, $srcY, $dstW, $dstH, $srcW, $srcH); } return ImageCopyResampled($dst_im, $src_im, $dstX, $dstY, $srcX, $srcY, $dstW, $dstH, $srcW, $srcH); } return ImageCopyResized($dst_im, $src_im, $dstX, $dstY, $srcX, $srcY, $dstW, $dstH, $srcW, $srcH); }
function MaxFileSize() { if (phpthumb_functions::gd_version() < 2) { return false; } if (!empty($this->maxb) && $this->maxb > 0) { switch ($this->thumbnailFormat) { case 'png': case 'gif': $imgRenderFunction = 'image' . $this->thumbnailFormat; ob_start(); $imgRenderFunction($this->gdimg_output); $imgdata = ob_get_contents(); ob_end_clean(); if (strlen($imgdata) > $this->maxb) { for ($i = 8; $i >= 1; $i--) { $tempIMG = ImageCreateTrueColor(ImageSX($this->gdimg_output), ImageSY($this->gdimg_output)); ImageCopy($tempIMG, $this->gdimg_output, 0, 0, 0, 0, ImageSX($this->gdimg_output), ImageSY($this->gdimg_output)); ImageTrueColorToPalette($tempIMG, true, pow(2, $i)); ob_start(); $imgRenderFunction($tempIMG); $imgdata = ob_get_contents(); ob_end_clean(); if (strlen($imgdata) <= $this->maxb) { ImageTrueColorToPalette($this->gdimg_output, true, pow(2, $i)); break; } } } if (strlen($imgdata) > $this->maxb) { ImageTrueColorToPalette($this->gdimg_output, true, pow(2, $i)); return false; } break; case 'jpeg': ob_start(); ImageJPEG($this->gdimg_output); $imgdata = ob_get_contents(); ob_end_clean(); $OriginalJPEGquality = $this->thumbnailQuality; if (strlen($imgdata) > $this->maxb) { for ($i = 3; $i < 20; $i++) { $q = round(100 * (1 - log10($i / 2))); ob_start(); ImageJPEG($this->gdimg_output, '', $q); $imgdata = ob_get_contents(); ob_end_clean(); $this->thumbnailQuality = $q; if (strlen($imgdata) <= $this->maxb) { break; } } } if (strlen($imgdata) > $this->maxb) { return false; } break; default: return false; break; } } return true; }
function Elipse($gdimg) { if (phpthumb_functions::gd_version() < 2) { return false; } // generate mask at twice desired resolution and downsample afterwards for easy antialiasing if ($gdimg_elipsemask_double = phpthumb_functions::ImageCreateFunction(ImageSX($gdimg) * 2, ImageSY($gdimg) * 2)) { if ($gdimg_elipsemask = phpthumb_functions::ImageCreateFunction(ImageSX($gdimg), ImageSY($gdimg))) { $color_transparent = ImageColorAllocate($gdimg_elipsemask_double, 255, 255, 255); ImageFilledEllipse($gdimg_elipsemask_double, ImageSX($gdimg), ImageSY($gdimg), (ImageSX($gdimg) - 1) * 2, (ImageSY($gdimg) - 1) * 2, $color_transparent); ImageCopyResampled($gdimg_elipsemask, $gdimg_elipsemask_double, 0, 0, 0, 0, ImageSX($gdimg), ImageSY($gdimg), ImageSX($gdimg) * 2, ImageSY($gdimg) * 2); phpthumb_filters::ApplyMask($gdimg_elipsemask, $gdimg); ImageDestroy($gdimg_elipsemask); return true; } else { //$this->DebugMessage('$gdimg_elipsemask = phpthumb_functions::ImageCreateFunction() failed', __FILE__, __LINE__); } ImageDestroy($gdimg_elipsemask_double); } else { //$this->DebugMessage('$gdimg_elipsemask_double = phpthumb_functions::ImageCreateFunction() failed', __FILE__, __LINE__); } return false; }
} elseif (in_array($key, $allowedGETparameters)) { $phpThumb->DebugMessage('setParameter(' . $key . ', ' . $phpThumb->phpThumbDebugVarDump($value) . ')', __FILE__, __LINE__); $phpThumb->setParameter($key, $value); } else { $phpThumb->ErrorImage('Forbidden parameter: ' . $key); } } //////////////////////////////////////////////////////////////// // Debug output, to try and help me diagnose problems $phpThumb->DebugTimingMessage('phpThumbDebug[3]', __FILE__, __LINE__); if (@$_GET['phpThumbDebug'] == '3') { $phpThumb->phpThumbDebug(); } //////////////////////////////////////////////////////////////// //if (!@$_GET['phpThumbDebug'] && !$phpThumb->sourceFilename && !function_exists('ImageJPEG') && !function_exists('ImagePNG') && !function_exists('ImageGIF')) { if (!@$_GET['phpThumbDebug'] && !is_file($phpThumb->sourceFilename) && !phpthumb_functions::gd_version()) { if (!headers_sent()) { // base64-encoded error image in GIF format $ERROR_NOGD = 'R0lGODlhIAAgALMAAAAAABQUFCQkJDY2NkZGRldXV2ZmZnJycoaGhpSUlKWlpbe3t8XFxdXV1eTk5P7+/iwAAAAAIAAgAAAE/vDJSau9WILtTAACUinDNijZtAHfCojS4W5H+qxD8xibIDE9h0OwWaRWDIljJSkUJYsN4bihMB8th3IToAKs1VtYM75cyV8sZ8vygtOE5yMKmGbO4jRdICQCjHdlZzwzNW4qZSQmKDaNjhUMBX4BBAlmMywFSRWEmAI6b5gAlhNxokGhooAIK5o/pi9vEw4Lfj4OLTAUpj6IabMtCwlSFw0DCKBoFqwAB04AjI54PyZ+yY3TD0ss2YcVmN/gvpcu4TOyFivWqYJlbAHPpOntvxNAACcmGHjZzAZqzSzcq5fNjxFmAFw9iFRunD1epU6tsIPmFCAJnWYE0FURk7wJDA0MTKpEzoWAAskiAAA7'; header('Content-Type: image/gif'); echo base64_decode($ERROR_NOGD); } else { echo '*** ERROR: No PHP-GD support available ***'; } exit; } // check to see if file can be output from source with no processing or caching $CanPassThroughDirectly = true; if ($phpThumb->rawImageData) { // data from SQL, should be fine } elseif (eregi('^(f|ht)tp\\://', $phpThumb->src)) {
function SourceImageToGD() { if (is_resource($this->gdimg_source)) { $this->DebugMessage('skipping SourceImageToGD() because $this->gdimg_source is already a resource', __FILE__, __LINE__); return true; } $this->DebugMessage('starting SourceImageToGD()', __FILE__, __LINE__); while (true) { if (!$this->config_use_exif_thumbnail_for_speed) { $this->DebugMessage('Not using EXIF thumbnail data because $this->config_use_exif_thumbnail_for_speed is FALSE', __FILE__, __LINE__); break; } if (!$this->exif_thumbnail_data) { $this->DebugMessage('Not using EXIF thumbnail data because $this->exif_thumbnail_data is empty', __FILE__, __LINE__); break; } if ($this->thumbnailCropX != 0 || $this->thumbnailCropY != 0) { $this->DebugMessage('Not using EXIF thumbnail data because source cropping is enabled (' . $this->thumbnailCropX . ',' . $this->thumbnailCropY . ')', __FILE__, __LINE__); break; } if ($this->w > $this->exif_thumbnail_width || $this->h > $this->exif_thumbnail_height) { $this->DebugMessage('Not using EXIF thumbnail data because EXIF thumbnail is too small (' . $this->exif_thumbnail_width . 'x' . $this->exif_thumbnail_height . ' vs ' . $this->w . 'x' . $this->h . ')', __FILE__, __LINE__); break; } $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__); } // EXIF thumbnail exists, and is equal to or larger than destination thumbnail, and will be use as source image $this->DebugMessage('Trying to use EXIF thumbnail as source image', __FILE__, __LINE__); if ($gdimg_exif_temp = $this->ImageCreateFromStringReplacement($this->exif_thumbnail_data, false)) { $this->DebugMessage('Successfully using EXIF thumbnail as source image', __FILE__, __LINE__); $this->gdimg_source = $gdimg_exif_temp; $this->source_width = $this->exif_thumbnail_width; $this->source_height = $this->exif_thumbnail_height; $this->thumbnailCropW = $this->source_width; $this->thumbnailCropH = $this->source_height; return true; } else { $this->DebugMessage('$this->ImageCreateFromStringReplacement($this->exif_thumbnail_data, false) failed', __FILE__, __LINE__); } break; } if (!$this->gdimg_source) { // try to create GD image source directly via GD, if possible, // rather than buffering to memory and creating with ImageCreateFromString $ImageCreateWasAttempted = false; $ImageCreateFromFunction = array(1 => 'ImageCreateFromGIF', 2 => 'ImageCreateFromJPEG', 3 => 'ImageCreateFromPNG', 15 => 'ImageCreateFromWBMP'); switch (@$this->getimagesizeinfo[2]) { case 1: // GIF // GIF case 2: // JPEG // JPEG case 3: // PNG // PNG case 15: // WBMP if ($this->md5s && $this->md5s != phpthumb_functions::md5_file_safe($this->sourceFilename)) { return $this->ErrorImage('$this->md5s != md5($this->rawImageData)' . "\n" . '"' . $this->md5s . '" != ' . "\n" . '"' . phpthumb_functions::md5_file_safe($this->sourceFilename) . '"'); } $ImageCreateFromFunctionName = $ImageCreateFromFunction[$this->getimagesizeinfo[2]]; if (function_exists($ImageCreateFromFunctionName)) { $this->DebugMessage('Calling ' . $ImageCreateFromFunctionName . '(' . $this->sourceFilename . ')', __FILE__, __LINE__); $ImageCreateWasAttempted = true; $this->gdimg_source = @$ImageCreateFromFunctionName($this->sourceFilename); switch ($this->getimagesizeinfo[2]) { case 1: case 3: // GIF or PNG input file may have transparency $this->is_alpha = true; break; } } else { $this->DebugMessage('NOT calling ' . $ImageCreateFromFunctionName . '(' . $this->sourceFilename . ') because !function_exists(' . $ImageCreateFromFunctionName . ')', __FILE__, __LINE__); } break; case 4: // SWF // SWF case 5: // PSD // PSD case 6: // BMP // BMP case 7: // TIFF (LE) // TIFF (LE) case 8: // TIFF (BE) // TIFF (BE) case 9: // JPC // JPC case 10: // JP2 // JP2 case 11: // JPX // JPX case 12: // JB2 // JB2 case 13: // SWC // SWC case 14: // IFF // IFF case 16: // XBM $this->DebugMessage('No built-in image creation function for image type "' . @$this->getimagesizeinfo[2] . '" ($this->getimagesizeinfo[2])', __FILE__, __LINE__); break; case '': // no source file, source image was probably set by setSourceData() break; default: $this->DebugMessage('Unknown value for $this->getimagesizeinfo[2]: "' . @$this->getimagesizeinfo[2] . '"', __FILE__, __LINE__); break; } if (!$this->gdimg_source) { // cannot create from filename, attempt to create source image with ImageCreateFromString, if possible if ($ImageCreateWasAttempted) { $this->DebugMessage(@$ImageCreateFromFunctionName . '() was attempted but FAILED', __FILE__, __LINE__); } if (!$this->rawImageData) { $this->DebugMessage('Populating $this->rawImageData and attempting ImageCreateFromStringReplacement()', __FILE__, __LINE__); if ($fp = @fopen($this->sourceFilename, 'rb')) { $this->rawImageData = ''; $filesize = filesize($this->sourceFilename); $blocksize = 16384; $blockreads = ceil($filesize / $blocksize); for ($i = 0; $i < $blockreads; $i++) { $this->rawImageData .= fread($fp, $blocksize); } fclose($fp); } else { return $this->ErrorImage('cannot fopen("' . $this->sourceFilename . '") on line ' . __LINE__ . ' of ' . __FILE__); } } if ($this->md5s && $this->md5s != md5($this->rawImageData)) { return $this->ErrorImage('$this->md5s != md5($this->rawImageData)' . "\n" . '"' . $this->md5s . '" != ' . "\n" . '"' . md5($this->rawImageData) . '"'); } $this->gdimg_source = $this->ImageCreateFromStringReplacement($this->rawImageData, true); } if (!$this->gdimg_source) { $this->DebugMessage('$this->gdimg_source is still empty', __FILE__, __LINE__); if ($this->ImageMagickThumbnailToGD()) { // excellent, we have a thumbnailed source image $this->DebugMessage('ImageMagickThumbnailToGD() succeeded', __FILE__, __LINE__); } else { $this->DebugMessage('ImageMagickThumbnailToGD() failed', __FILE__, __LINE__); $imageHeader = ''; $gd_info = phpthumb_functions::gd_info(); $GDreadSupport = false; switch (substr($this->rawImageData, 0, 3)) { case 'GIF': $imageHeader = 'Content-Type: image/gif'; $GDreadSupport = (bool) @$gd_info['GIF Read Support']; break; case "ÿØÿ": $imageHeader = 'Content-Type: image/jpeg'; $GDreadSupport = (bool) @$gd_info['JPG Support']; break; case "‰" . 'PN': $imageHeader = 'Content-Type: image/png'; $GDreadSupport = (bool) @$gd_info['PNG Support']; break; } if ($imageHeader) { // cannot create image for whatever reason (maybe ImageCreateFromJPEG et al are not available?) // and ImageMagick is not available either, no choice but to output original (not resized/modified) data and exit if ($this->config_error_die_on_source_failure && !$this->phpThumbDebug) { $this->ErrorImage('All attempts to create GD image source failed (' . ($GDreadSupport ? 'source image probably corrupt' : 'GD does not have read support for "' . $imageHeader . '"') . '), cannot generate thumbnail'); } else { //$this->DebugMessage('All attempts to create GD image source failed ('.($GDreadSupport ? 'source image probably corrupt' : 'GD does not have read support for "'.$imageHeader.'"').'), outputing raw image', __FILE__, __LINE__); //if (!$this->phpThumbDebug) { // header($imageHeader); // echo $this->rawImageData; // exit; //} return false; } } switch (substr($this->rawImageData, 0, 2)) { case 'BM': ob_start(); if (!@(include_once dirname(__FILE__) . '/phpthumb.bmp.php')) { ob_end_clean(); if ($this->phpThumbDebug) { $this->DebugMessage('include_once(' . dirname(__FILE__) . '/phpthumb.bmp.php) failed', __FILE__, __LINE__); return false; } return $this->ErrorImage('include_once(' . dirname(__FILE__) . '/phpthumb.bmp.php) failed'); } ob_end_clean(); $phpthumb_bmp = new phpthumb_bmp(); if ($this->gdimg_source = $phpthumb_bmp->phpthumb_bmp2gd($this->rawImageData, phpthumb_functions::gd_version() >= 2.0)) { $this->DebugMessage('$phpthumb_bmp->phpthumb_bmp2gd() succeeded', __FILE__, __LINE__); break; } elseif ($this->phpThumbDebug) { $this->DebugMessage('phpthumb_bmp2db failed', __FILE__, __LINE__); return false; } return $this->ErrorImage('ImageMagick is unavailable and phpThumb() does not support BMP source images without it'); break; } switch (substr($this->rawImageData, 0, 4)) { case 'II' . "*": case 'MM' . "*": if ($this->phpThumbDebug) { $this->DebugMessage('ImageMagick is unavailable and phpThumb() does not support TIFF source images without it', __FILE__, __LINE__); return false; } return $this->ErrorImage('ImageMagick is unavailable and phpThumb() does not support TIFF source images without it'); break; case "×ÍÆš": if ($this->phpThumbDebug) { $this->DebugMessage('ImageMagick is unavailable and phpThumb() does not support WMF source images without it', __FILE__, __LINE__); return false; } return $this->ErrorImage('ImageMagick is unavailable and phpThumb() does not support WMF source images without it'); break; } if (!$this->gdimg_source) { if ($this->phpThumbDebug) { $this->DebugMessage('Unknown image type identified by "' . substr($this->rawImageData, 0, 4) . '" (' . phpthumb_functions::HexCharDisplay(substr($this->rawImageData, 0, 4)) . ') in SourceImageToGD()', __FILE__, __LINE__); return false; } return $this->ErrorImage('Unknown image type identified by "' . substr($this->rawImageData, 0, 4) . '" (' . phpthumb_functions::HexCharDisplay(substr($this->rawImageData, 0, 4)) . ') in SourceImageToGD()'); } } } } if (!$this->gdimg_source) { if ($gdimg_exif_temp = $this->ImageCreateFromStringReplacement($this->exif_thumbnail_data, false)) { $this->DebugMessage('All other attempts failed, but successfully using EXIF thumbnail as source image', __FILE__, __LINE__); $this->gdimg_source = $gdimg_exif_temp; // 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->aoe = true; return true; } return false; } $this->source_width = ImageSX($this->gdimg_source); $this->source_height = ImageSY($this->gdimg_source); return true; }
function gd_missing() { require_once PLOGGER_DIR . '/plog-includes/lib/phpthumb/phpthumb.functions.php'; // This is copied over from phpthumb return phpthumb_functions::gd_version() < 1; }
<?php $GDversion['string'] = 'unknown'; $GDversion['numeric'] = 0; if (!@(include_once 'phpthumb.functions.php')) { die('failed to open "phpthumb.functions.php"'); } if (include_once 'phpthumb.class.php') { $phpThumb = new phpThumb(); $phpthumb_version = $phpThumb->phpthumb_version; unset($phpThumb); $GDversion['string'] = phpthumb_functions::gd_version(true); $GDversion['numeric'] = phpthumb_functions::gd_version(false); } else { die('failed to open "phpthumb.class.php"'); } ?> <html> <head> <title>Demo of phpThumb() - thumbnails created by PHP</title> <link rel="stylesheet" type="text/css" href="/style.css" title="style sheet"> </head> <body bgcolor="#C5C5C5"> This is a demo of <a href="http://phpthumb.sourceforge.net"><b>phpThumb()</b></a> (current version: v<?php echo @$phpthumb_version; ?> )<br> A dynamic demo where you can set <strike>all</strike> some of the parmeters and see their effect is <a href="phpThumb.demo.demo2.php">here</a>.<br> <br>
function SourceImageToGD() { if (is_resource($this->gdimg_source)) { $this->DebugMessage('skipping SourceImageToGD() because $this->gdimg_source is already a resource', __FILE__, __LINE__); return true; } $this->DebugMessage('starting SourceImageToGD()', __FILE__, __LINE__); if ($this->config_use_exif_thumbnail_for_speed && !empty($this->exif_thumbnail_data)) { if ($this->exif_thumbnail_width >= $this->thumbnail_image_width && $this->exif_thumbnail_height >= $this->thumbnail_image_height && $this->thumbnailCropX == 0 && $this->thumbnailCropY == 0 && $this->thumbnailCropW > 0 && $this->thumbnailCropH > 0 && $this->source_width >= $this->thumbnailCropW && $this->source_height >= $this->thumbnailCropH) { // EXIF thumbnail exists, and is equal to or larger than destination thumbnail, and will be use as source image // Only benefit here is greater speed, not lower memory usage $this->DebugMessage('Trying to use EXIF thumbnail as source image', __FILE__, __LINE__); if ($gdimg_exif_temp = $this->ImageCreateFromStringReplacement($this->exif_thumbnail_data, false)) { $this->DebugMessage('Successfully using EXIF thumbnail as source image', __FILE__, __LINE__); $this->gdimg_source = $gdimg_exif_temp; $this->source_width = $this->exif_thumbnail_width; $this->source_height = $this->exif_thumbnail_height; $this->thumbnailCropW = $this->source_width; $this->thumbnailCropH = $this->source_height; return true; } else { $this->DebugMessage('$this->ImageCreateFromStringReplacement($this->exif_thumbnail_data, false) failed', __FILE__, __LINE__); } } else { $this->DebugMessage('Not using EXIF thumbnail data because EXIF thumbnail is too small', __FILE__, __LINE__); } } else { if (!$this->config_use_exif_thumbnail_for_speed) { $this->DebugMessage('Not using EXIF thumbnail data because $this->config_use_exif_thumbnail_for_speed is FALSE', __FILE__, __LINE__); } elseif ($this->getimagesizeinfo[2] == 2) { $this->DebugMessage('Not using EXIF thumbnail data because EXIF thumbnail is unavailable', __FILE__, __LINE__); } elseif (is_array($this->getimagesizeinfo)) { $this->DebugMessage('Not using EXIF thumbnail data because source image is not JPEG, therefore no EXIF thumbnail available', __FILE__, __LINE__); //} else { // $this->DebugMessage('Not using EXIF thumbnail data because GetImageSize failed on source image', __FILE__, __LINE__); } } if (empty($this->gdimg_source)) { // try to create GD image source directly via GD, if possible, // rather than buffering to memory and creating with ImageCreateFromString $ImageCreateWasAttempted = false; if (!empty($this->rawImageData)) { // fine } elseif ($this->iswindows && (substr($this->sourceFilename, 0, 2) == '//' || substr($this->sourceFilename, 0, 2) == '\\\\')) { // Windows \\share\filename.ext } elseif (eregi('^(f|ht)tp[s]?://', $this->sourceFilename)) { // URL } elseif (!file_exists($this->sourceFilename)) { return $this->ErrorImage('"' . $this->sourceFilename . '" does not exist'); } elseif (!is_file($this->sourceFilename)) { return $this->ErrorImage('"' . $this->sourceFilename . '" is not a file'); } $ImageCreateFromFunction = array(1 => 'ImageCreateFromGIF', 2 => 'ImageCreateFromJPEG', 3 => 'ImageCreateFromPNG', 15 => 'ImageCreateFromWBMP'); switch (@$this->getimagesizeinfo[2]) { case 1: // GIF // GIF case 2: // JPEG // JPEG case 3: // PNG // PNG case 15: // WBMP $ImageCreateFromFunctionName = $ImageCreateFromFunction[$this->getimagesizeinfo[2]]; if (function_exists($ImageCreateFromFunctionName)) { $this->DebugMessage('Calling ' . $ImageCreateFromFunctionName . '(' . $this->sourceFilename . ')', __FILE__, __LINE__); $ImageCreateWasAttempted = true; $this->gdimg_source = @$ImageCreateFromFunctionName($this->sourceFilename); switch ($this->getimagesizeinfo[2]) { case 1: case 3: // GIF or PNG input file may have transparency $this->is_alpha = true; break; } } else { $this->DebugMessage('NOT calling ' . $ImageCreateFromFunctionName . '(' . $this->sourceFilename . ') because !function_exists(' . $ImageCreateFromFunctionName . ')', __FILE__, __LINE__); } break; case 4: // SWF // SWF case 5: // PSD // PSD case 6: // BMP // BMP case 7: // TIFF (LE) // TIFF (LE) case 8: // TIFF (BE) // TIFF (BE) case 9: // JPC // JPC case 10: // JP2 // JP2 case 11: // JPX // JPX case 12: // JB2 // JB2 case 13: // SWC // SWC case 14: // IFF // IFF case 16: // XBM $this->DebugMessage('No built-in image creation function for image type "' . @$this->getimagesizeinfo[2] . '" ($this->getimagesizeinfo[2])', __FILE__, __LINE__); break; case '': // no source file, source image was probably set by setSourceData() break; default: $this->DebugMessage('Unknown value for $this->getimagesizeinfo[2]: "' . @$this->getimagesizeinfo[2] . '"', __FILE__, __LINE__); break; } if (empty($this->gdimg_source)) { // cannot create from filename, attempt to create source image with ImageCreateFromString, if possible if ($ImageCreateWasAttempted) { $this->DebugMessage(@$ImageCreateFromFunctionName . '() was attempted but FAILED', __FILE__, __LINE__); } if (empty($this->rawImageData)) { $this->DebugMessage('Populating $this->rawImageData and attempting ImageCreateFromStringReplacement()', __FILE__, __LINE__); if ($fp = @fopen($this->sourceFilename, 'rb')) { $this->rawImageData = ''; $filesize = filesize($this->sourceFilename); $blocksize = 16384; $blockreads = ceil($filesize / $blocksize); for ($i = 0; $i < $blockreads; $i++) { $this->rawImageData .= fread($fp, $blocksize); } fclose($fp); } else { return $this->ErrorImage('cannot fopen("' . $this->sourceFilename . '") on line ' . __LINE__ . ' of ' . __FILE__); } } $this->gdimg_source = $this->ImageCreateFromStringReplacement($this->rawImageData, true); } if (empty($this->gdimg_source)) { $this->DebugMessage('$this->gdimg_source is still empty', __FILE__, __LINE__); if ($this->ImageMagickThumbnailToGD()) { // excellent, we have a thumbnailed source image $this->DebugMessage('ImageMagickThumbnailToGD() succeeded', __FILE__, __LINE__); } else { $this->DebugMessage('ImageMagickThumbnailToGD() failed', __FILE__, __LINE__); $imageHeader = ''; switch (substr($this->rawImageData, 0, 3)) { case 'GIF': $imageHeader = 'Content-type: image/gif'; break; case "ÿØÿ": $imageHeader = 'Content-type: image/jpeg'; break; case "‰" . 'PN': $imageHeader = 'Content-type: image/png'; break; } if ($imageHeader) { // cannot create image for whatever reason (maybe ImageCreateFromJPEG et al are not available?) // and ImageMagick is not available either, no choice but to output original (not resized/modified) data and exit if ($this->config_error_die_on_source_failure) { $this->ErrorImage('All attempts to create GD image source failed (source image probably corrupt), cannot generate thumbnail'); } else { $this->DebugMessage('All attempts to create GD image source failed, outputing raw image', __FILE__, __LINE__); header($imageHeader); echo $this->rawImageData; exit; } } switch (substr($this->rawImageData, 0, 2)) { case 'BM': if (@(include_once 'phpthumb.bmp.php')) { $phpthumb_bmp = new phpthumb_bmp(); if ($this->gdimg_source = $phpthumb_bmp->phpthumb_bmp2gd($this->rawImageData, phpthumb_functions::gd_version() >= 2.0)) { $this->DebugMessage('$phpthumb_bmp->phpthumb_bmp2gd() succeeded', __FILE__, __LINE__); break; } else { return $this->ErrorImage('phpthumb_bmp2db failed'); } } else { return $this->ErrorImage('include_once(phpthumb.bmp.php) failed'); } return $this->ErrorImage('ImageMagick is unavailable and phpThumb() does not support BMP source images without it'); break; } switch (substr($this->rawImageData, 0, 4)) { case 'II' . "*": case 'MM' . "*": return $this->ErrorImage('ImageMagick is unavailable and phpThumb() does not support TIFF source images without it'); break; case "×ÍÆš": return $this->ErrorImage('ImageMagick is unavailable and phpThumb() does not support WMF source images without it'); break; } if (empty($this->gdimg_source)) { return $this->ErrorImage('Unknown image type identified by "' . substr($this->rawImageData, 0, 4) . '" (' . phpthumb_functions::HexCharDisplay(substr($this->rawImageData, 0, 4)) . ') in SourceImageToGD()'); } } } } $this->source_width = ImageSX($this->gdimg_source); $this->source_height = ImageSY($this->gdimg_source); return true; }
function gd_missing() { require_once dirname(__FILE__) . '/../../lib/phpthumb/phpthumb.functions.php'; // this is copied over from phpthumb return phpthumb_functions::gd_version() < 1; }