function RedirectToCachedFile() { global $phpThumb, $PHPTHUMB_CONFIG; $nice_cachefile = str_replace(DIRECTORY_SEPARATOR, '/', $phpThumb->cache_filename); $nice_docroot = str_replace(DIRECTORY_SEPARATOR, '/', rtrim($PHPTHUMB_CONFIG['document_root'], '/\\')); $parsed_url = phpThumb_functions::ParseURLbetter(@$_SERVER['HTTP_REFERER']); $nModified = filemtime($phpThumb->cache_filename); if ($phpThumb->config_nooffsitelink_enabled && @$_SERVER['HTTP_REFERER'] && !in_array(@$parsed_url['host'], $phpThumb->config_nooffsitelink_valid_domains)) { $phpThumb->DebugMessage('Would have used cached (image/' . $phpThumb->thumbnailFormat . ') file "' . $phpThumb->cache_filename . '" (Last-Modified: ' . gmdate('D, d M Y H:i:s', $nModified) . ' GMT), but skipping because $_SERVER[HTTP_REFERER] (' . @$_SERVER['HTTP_REFERER'] . ') is not in $phpThumb->config_nooffsitelink_valid_domains (' . implode(';', $phpThumb->config_nooffsitelink_valid_domains) . ')', __FILE__, __LINE__); } elseif ($phpThumb->phpThumbDebug) { $phpThumb->DebugTimingMessage('skipped using cached image', __FILE__, __LINE__); $phpThumb->DebugMessage('Would have used cached file, but skipping due to phpThumbDebug', __FILE__, __LINE__); $phpThumb->DebugMessage('* Would have sent headers (1): Last-Modified: ' . gmdate('D, d M Y H:i:s', $nModified) . ' GMT', __FILE__, __LINE__); if ($getimagesize = @GetImageSize($phpThumb->cache_filename)) { $phpThumb->DebugMessage('* Would have sent headers (2): Content-Type: ' . phpThumb_functions::ImageTypeToMIMEtype($getimagesize[2]), __FILE__, __LINE__); } if (preg_match('#^' . preg_quote($nice_docroot) . '(.*)$#', $nice_cachefile, $matches)) { $phpThumb->DebugMessage('* Would have sent headers (3): Location: ' . dirname($matches[1]) . '/' . urlencode(basename($matches[1])), __FILE__, __LINE__); } else { $phpThumb->DebugMessage('* Would have sent data: readfile(' . $phpThumb->cache_filename . ')', __FILE__, __LINE__); } } else { if (headers_sent()) { $phpThumb->ErrorImage('Headers already sent (' . basename(__FILE__) . ' line ' . __LINE__ . ')'); exit; } SendSaveAsFileHeaderIfNeeded(); header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $nModified) . ' GMT'); if (@$_SERVER['HTTP_IF_MODIFIED_SINCE'] && $nModified == strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) && @$_SERVER['SERVER_PROTOCOL']) { header($_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified'); exit; } if ($getimagesize = @GetImageSize($phpThumb->cache_filename)) { header('Content-Type: ' . phpThumb_functions::ImageTypeToMIMEtype($getimagesize[2])); } elseif (preg_match('#\\.ico$#i', $phpThumb->cache_filename)) { header('Content-Type: image/x-icon'); } if (!@$PHPTHUMB_CONFIG['cache_force_passthru'] && preg_match('#^' . preg_quote($nice_docroot) . '(.*)$#', $nice_cachefile, $matches)) { header('Location: ' . dirname($matches[1]) . '/' . urlencode(basename($matches[1]))); } else { @readfile($phpThumb->cache_filename); } exit; } return true; }
echo 'orange'; } elseif ($php_sapi_name == 'cgi') { echo 'yellow'; } elseif ($php_sapi_name == 'apache') { echo 'lime'; } else { echo 'green'; } echo ';">' . htmlentities($php_sapi_name) . '</th>'; echo '<td>SAPI mode preferred to CGI mode. FCGI mode has unconfirmed strange behavior (notably more than one space in "wmt" filter text causes errors). If not working in "apache" (SAPI) mode, <i>apache_lookup_uri()</i> will not work.</td></tr>'; echo '<tr><th>Server Software</th><th colspan="2" style="background-color: '; $server_software = getenv('SERVER_SOFTWARE'); if (!$server_software) { echo 'red'; } elseif (preg_match('#^Apache/([0-9\\.]+)#i', $server_software, $matches)) { if (phpThumb_functions::version_compare_replacement($matches[1], '2.0.0', '>=')) { echo 'lightgreen'; } else { echo 'lime'; } } else { echo 'darkgreen'; } echo ';">' . $server_software . '</th>'; echo '<td>Apache v1.x has the fewest compatability problems. IIS has numerous annoyances. Apache v2.x is broken when lookup up <i>/~user/filename.jpg</i> style relative filenames using <i>apache_lookup_uri()</i>.</td></tr>'; echo '<tr><th>curl_version:</th><th colspan="2" style="background-color: '; $curl_version = function_exists('curl_version') ? curl_version() : ''; if (is_array($curl_version)) { $curl_version = @$curl_version['version']; } if ($curl_version) {
function WatermarkOverlay(&$gdimg_dest, &$img_watermark, $alignment = '*', $opacity = 50, $margin_x = 5, $margin_y = null) { if (is_resource($gdimg_dest) && is_resource($img_watermark)) { $watermark_source_x = 0; $watermark_source_y = 0; $img_source_width = ImageSX($gdimg_dest); $img_source_height = ImageSY($gdimg_dest); $watermark_source_width = ImageSX($img_watermark); $watermark_source_height = ImageSY($img_watermark); $watermark_opacity_percent = max(0, min(100, $opacity)); $margin_y = is_null($margin_y) ? $margin_x : $margin_y; $watermark_margin_x = $margin_x > 0 && $margin_x < 1 ? round((1 - $margin_x) * $img_source_width) : $margin_x; $watermark_margin_y = $margin_y > 0 && $margin_y < 1 ? round((1 - $margin_y) * $img_source_height) : $margin_y; if (preg_match('#^([0-9\\.\\-]*)x([0-9\\.\\-]*)$#i', $alignment, $matches)) { $watermark_destination_x = intval($matches[1]); $watermark_destination_y = intval($matches[2]); } else { switch ($alignment) { case '*': if ($gdimg_tiledwatermark = phpThumb_functions::ImageCreateFunction($img_source_width, $img_source_height)) { ImageAlphaBlending($gdimg_tiledwatermark, false); ImageSaveAlpha($gdimg_tiledwatermark, true); $text_color_transparent = phpThumb_functions::ImageColorAllocateAlphaSafe($gdimg_tiledwatermark, 255, 0, 255, 127); ImageFill($gdimg_tiledwatermark, 0, 0, $text_color_transparent); // set the tiled image transparent color to whatever the untiled image transparency index is // ImageColorTransparent($gdimg_tiledwatermark, ImageColorTransparent($img_watermark)); // a "cleaner" way of doing it, but can't handle the margin feature :( // ImageSetTile($gdimg_tiledwatermark, $img_watermark); // ImageFill($gdimg_tiledwatermark, 0, 0, IMG_COLOR_TILED); // break; // ImageFill($gdimg_tiledwatermark, 0, 0, ImageColorTransparent($gdimg_tiledwatermark)); // tile the image as many times as can fit for ($x = $watermark_margin_x; $x < $img_source_width + $watermark_source_width; $x += $watermark_source_width + $watermark_margin_x) { for ($y = $watermark_margin_y; $y < $img_source_height + $watermark_source_height; $y += $watermark_source_height + $watermark_margin_y) { ImageCopy($gdimg_tiledwatermark, $img_watermark, $x, $y, 0, 0, min($watermark_source_width, $img_source_width - $x - $watermark_margin_x), min($watermark_source_height, $img_source_height - $y - $watermark_margin_y)); } } $watermark_source_width = ImageSX($gdimg_tiledwatermark); $watermark_source_height = ImageSY($gdimg_tiledwatermark); $watermark_destination_x = 0; $watermark_destination_y = 0; ImageDestroy($img_watermark); $img_watermark = $gdimg_tiledwatermark; } break; case 'T': $watermark_destination_x = round($img_source_width / 2 - $watermark_source_width / 2 + $watermark_margin_x); $watermark_destination_y = $watermark_margin_y; break; case 'B': $watermark_destination_x = round($img_source_width / 2 - $watermark_source_width / 2 + $watermark_margin_x); $watermark_destination_y = $img_source_height - $watermark_source_height - $watermark_margin_y; break; case 'L': $watermark_destination_x = $watermark_margin_x; $watermark_destination_y = round($img_source_height / 2 - $watermark_source_height / 2 + $watermark_margin_y); break; case 'R': $watermark_destination_x = $img_source_width - $watermark_source_width - $watermark_margin_x; $watermark_destination_y = round($img_source_height / 2 - $watermark_source_height / 2 + $watermark_margin_y); break; case 'C': $watermark_destination_x = round($img_source_width / 2 - $watermark_source_width / 2); $watermark_destination_y = round($img_source_height / 2 - $watermark_source_height / 2); break; case 'TL': $watermark_destination_x = $watermark_margin_x; $watermark_destination_y = $watermark_margin_y; break; case 'TR': $watermark_destination_x = $img_source_width - $watermark_source_width - $watermark_margin_x; $watermark_destination_y = $watermark_margin_y; break; case 'BL': //echo '<pre>'; ////var_dump($watermark_destination_x); ////var_dump($watermark_destination_y); //var_dump($watermark_margin_x); //var_dump($img_source_height); //var_dump($watermark_source_height); //var_dump($watermark_margin_y); $watermark_destination_x = $watermark_margin_x; $watermark_destination_y = $img_source_height - $watermark_source_height - $watermark_margin_y; break; case 'BR': default: $watermark_destination_x = $img_source_width - $watermark_source_width - $watermark_margin_x; $watermark_destination_y = $img_source_height - $watermark_source_height - $watermark_margin_y; break; } } ImageAlphaBlending($gdimg_dest, false); ImageSaveAlpha($gdimg_dest, true); ImageSaveAlpha($img_watermark, true); phpThumb_functions::ImageCopyRespectAlpha($gdimg_dest, $img_watermark, $watermark_destination_x, $watermark_destination_y, 0, 0, $watermark_source_width, $watermark_source_height, $watermark_opacity_percent); return true; } return false; }
function PlotBMP(&$BMPinfo) { $starttime = time(); if (!isset($BMPinfo['bmp']['data']) || !is_array($BMPinfo['bmp']['data'])) { echo 'ERROR: no pixel data<BR>'; return false; } if (!phpThumb_functions::FunctionIsDisabled('set_time_limit')) { set_time_limit(intval(round($BMPinfo['resolution_x'] * $BMPinfo['resolution_y'] / 10000))); } $im = $this->PlotPixelsGD($BMPinfo['bmp']); if (headers_sent()) { echo 'plotted ' . $BMPinfo['resolution_x'] * $BMPinfo['resolution_y'] . ' pixels in ' . (time() - $starttime) . ' seconds<BR>'; ImageDestroy($im); exit; } else { header('Content-Type: image/png'); ImagePNG($im); ImageDestroy($im); return true; } return false; }
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); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <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"> <link rel="shortcut icon" type="image/x-icon" href="http://phpThumb.sourceforge.net/thumb.ico"> <meta http-equiv="Content-type" content="text/html;charset=UTF-8"> </head> <body style="background-color: #C5C5C5;"> This is a demo of <a href="http://phpThumb.sourceforge.net"><b>phpThumb()</b></a> (current version: v<?php echo @$ServerInfo['phpThumb_version'];
static function SanitizeFilename($filename) { $filename = preg_replace('/[^' . preg_quote(' !#$%^()+,-.;<>=@[]_{}') . 'a-zA-Z0-9]/', '_', $filename); if (phpThumb_functions::version_compare_replacement(phpversion(), '4.1.0', '>=')) { $filename = trim($filename, '.'); } return $filename; }
function GD2ICOstring(&$gd_image_array) { foreach ($gd_image_array as $key => $gd_image) { $ImageWidths[$key] = ImageSX($gd_image); $ImageHeights[$key] = ImageSY($gd_image); $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24; $totalcolors[$key] = ImageColorsTotal($gd_image); $icXOR[$key] = ''; for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) { for ($x = 0; $x < $ImageWidths[$key]; $x++) { $argb = phpThumb_functions::GetPixelColor($gd_image, $x, $y); $a = round(255 * ((127 - $argb['alpha']) / 127)); $r = $argb['red']; $g = $argb['green']; $b = $argb['blue']; if ($bpp[$key] == 32) { $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a); } elseif ($bpp[$key] == 24) { $icXOR[$key] .= chr($b) . chr($g) . chr($r); } if ($a < 128) { @($icANDmask[$key][$y] .= '1'); } else { @($icANDmask[$key][$y] .= '0'); } } // mask bits are 32-bit aligned per scanline while (strlen($icANDmask[$key][$y]) % 32) { $icANDmask[$key][$y] .= '0'; } } $icAND[$key] = ''; foreach ($icANDmask[$key] as $y => $scanlinemaskbits) { for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) { $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT))); } } } foreach ($gd_image_array as $key => $gd_image) { $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8); // BITMAPINFOHEADER - 40 bytes $BitmapInfoHeader[$key] = ''; $BitmapInfoHeader[$key] .= "("; // DWORD biSize; $BitmapInfoHeader[$key] .= phpThumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; // The biHeight member specifies the combined // height of the XOR and AND masks. $BitmapInfoHeader[$key] .= phpThumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG biHeight; $BitmapInfoHeader[$key] .= ""; // WORD biPlanes; $BitmapInfoHeader[$key] .= chr($bpp[$key]) . ""; // wBitCount; $BitmapInfoHeader[$key] .= ""; // DWORD biCompression; $BitmapInfoHeader[$key] .= phpThumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; $BitmapInfoHeader[$key] .= ""; // LONG biXPelsPerMeter; $BitmapInfoHeader[$key] .= ""; // LONG biYPelsPerMeter; $BitmapInfoHeader[$key] .= ""; // DWORD biClrUsed; $BitmapInfoHeader[$key] .= ""; // DWORD biClrImportant; } $icondata = ""; // idReserved; // Reserved (must be 0) $icondata .= ""; // idType; // Resource Type (1 for icons) $icondata .= phpThumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? $dwImageOffset = 6 + count($gd_image_array) * 16; foreach ($gd_image_array as $key => $gd_image) { // ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em) $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) $icondata .= ""; // bReserved; // Reserved ( must be 0) $icondata .= ""; // wPlanes; // Color Planes $icondata .= chr($bpp[$key]) . ""; // wBitCount; // Bits per pixel $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]); $icondata .= phpThumb_functions::LittleEndian2String($dwBytesInRes, 4); // dwBytesInRes; // How many bytes in this resource? $icondata .= phpThumb_functions::LittleEndian2String($dwImageOffset, 4); // dwImageOffset; // Where in the file is this image? $dwImageOffset += strlen($BitmapInfoHeader[$key]); $dwImageOffset += strlen($icXOR[$key]); $dwImageOffset += strlen($icAND[$key]); } foreach ($gd_image_array as $key => $gd_image) { $icondata .= $BitmapInfoHeader[$key]; $icondata .= $icXOR[$key]; $icondata .= $icAND[$key]; } return $icondata; }
$PHPTHUMB_CONFIG['temp_directory'] = $PHPTHUMB_CONFIG['cache_directory']; // set to same as cache directory // NOTE: "max_source_pixels" only affects GD-resized thumbnails. If you have ImageMagick // installed it will bypass most of these limits // maximum number of pixels in source image to attempt to process entire image in GD mode. // If this is zero then no limit on source image dimensions. // If this is nonzero then this is the maximum number of pixels the source image // can have to be processed normally, otherwise the embedded EXIF thumbnail will // be used (if available) or an "image too large" notice will be displayed. // This is to be used for large source images (> 1600x1200) and low PHP memory // limits. If PHP runs out of memory the script will usually just die with no output. // To calculate this number, multiply the dimensions of the largest image // you can process with your memory limitation (e.g. 1600 * 1200 = 1920000) // As a general guideline, this number will be about 20% of your PHP memory // configuration, so 8M = 1,677,722; 16M = 3,355,443; 32M = 6,710,886; etc. if (phpThumb_functions::version_compare_replacement(phpversion(), '4.3.2', '>=') && !defined('memory_get_usage') && !@ini_get('memory_limit')) { // memory_get_usage() will only be defined if your PHP is compiled with the --enable-memory-limit configuration option. $PHPTHUMB_CONFIG['max_source_pixels'] = 0; // no memory limit } else { // calculate default max_source_pixels as 1/6 of memory limit configuration $PHPTHUMB_CONFIG['max_source_pixels'] = round(max(intval(ini_get('memory_limit')), intval(get_cfg_var('memory_limit'))) * 1048576 / 6); //$PHPTHUMB_CONFIG['max_source_pixels'] = 0; // no memory limit //$PHPTHUMB_CONFIG['max_source_pixels'] = 1920000; // allow 1600x1200 images (2Mpx), no larger (about 12MB memory required) //$PHPTHUMB_CONFIG['max_source_pixels'] = 2795000; // 16MB memory limit //$PHPTHUMB_CONFIG['max_source_pixels'] = 3871488; // allow 2272x1704 images (4Mpx), no larger (about 24MB memory required) } // ImageMagick configuration $PHPTHUMB_CONFIG['prefer_imagemagick'] = true; // If true, use ImageMagick to resize thumbnails if possible, since it is usually faster than GD functions; if false only use ImageMagick if PHP memory limit is too low. $PHPTHUMB_CONFIG['imagemagick_use_thumbnail'] = true;