Beispiel #1
0
function RedirectToCachedFile()
{
    global $phpThumb;
    $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 && !empty($_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('Pragma: private');
        header('Cache-Control: max-age=' . $phpThumb->getParameter('config_cache_maxage'));
        header('Expires: ' . date(DATE_RFC1123, time() + $phpThumb->getParameter('config_cache_maxage')));
        if (!empty($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $nModified == strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) && !empty($_SERVER['SERVER_PROTOCOL'])) {
            header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $nModified) . ' GMT');
            header($_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified');
            exit;
        }
        header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $nModified) . ' GMT');
        header('ETag: "' . md5_file($phpThumb->cache_filename) . '"');
        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');
        }
        header('Content-Length: ' . filesize($phpThumb->cache_filename));
        if (empty($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;
}
function SendSaveAsFileHeaderIfNeeded()
{
    if (!empty($_GET['down'])) {
        $downloadfilename = ereg_replace('[/\\:\\*\\?"<>|]', '_', $_GET['down']);
        if (phpthumb_functions::version_compare_replacement(phpversion(), '4.1.0', '>=')) {
            $downloadfilename = trim($downloadfilename, '.');
        }
        if (!empty($downloadfilename)) {
            header('Content-Disposition: attachment; filename="' . $downloadfilename . '"');
        }
    }
    return true;
}
Beispiel #3
0
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;
    }
}
Beispiel #4
0
 public function dump($preConf)
 {
     $imgDirecoryPrefix = $this->getTrackId() ? APP_ROOT : \Slim\Slim::getInstance()->config['mpd']['musicdir'];
     $phpThumb = self::getPhpThumb();
     $phpThumb->setSourceFilename($imgDirecoryPrefix . $this->getRelativePath());
     $phpThumb->setParameter('config_output_format', 'jpg');
     switch ($preConf) {
         case 50:
         case 100:
         case 300:
         case 1000:
             $phpThumb->setParameter('w', $preConf);
             break;
         default:
             $phpThumb->setParameter('w', 300);
     }
     $phpThumb->SetCacheFilename();
     // check if we already have a cached image
     if (is_file($phpThumb->cache_filename) === FALSE || is_readable($phpThumb->cache_filename) === FALSE) {
         $phpThumb->GenerateThumbnail();
         \phpthumb_functions::EnsureDirectoryExists(dirname($phpThumb->cache_filename));
         $phpThumb->RenderToFile($phpThumb->cache_filename);
         if (is_file($phpThumb->cache_filename) === TRUE) {
             chmod($phpThumb->cache_filename, 0777);
         } else {
             // something went wrong
             // TODO: how to handle this?
             // TODO: make sure we have no infinite loop...
             return self::getFallbackImage()->dump($preConf);
         }
     }
     #\Slim\Slim::getInstance()->response()->headers->set('Content-Type', 'image/jpeg');
     header('Content-Type: image/jpeg');
     readfile($phpThumb->cache_filename);
     exit;
 }
Beispiel #5
0
 private function generatePeakFile()
 {
     // extract peaks
     $peakValues = $this->getPeaks();
     // shorten values to configured limit
     $peakValues = $this->limitArray($peakValues, $this->peakFileResolution);
     \phpthumb_functions::EnsureDirectoryExists(dirname($this->peakValuesFilePath));
     file_put_contents($this->peakValuesFilePath, join("\n", $peakValues));
     return;
 }
 function ImageCreateFromStringReplacement(&$RawImageData, $DieOnErrors = false)
 {
     // there are serious bugs in the non-bundled versions of GD which may cause
     // PHP to segfault when calling ImageCreateFromString() - avoid if at all possible
     // when not using a bundled version of GD2
     $gd_info = phpthumb_functions::gd_info();
     if (strpos($gd_info['GD Version'], 'bundled') !== false) {
         return @ImageCreateFromString($RawImageData);
     }
     switch (substr($RawImageData, 0, 3)) {
         case 'GIF':
             $ICFSreplacementFunctionName = 'ImageCreateFromGIF';
             break;
         case "ÿØÿ":
             $ICFSreplacementFunctionName = 'ImageCreateFromJPEG';
             break;
         case "‰" . 'PN':
             $ICFSreplacementFunctionName = 'ImageCreateFromPNG';
             break;
         default:
             $this->ErrorImage('Unknown image type identified by "' . substr($this->rawImageData, 0, 3) . '" (' . phpthumb_functions::HexCharDisplay(substr($this->rawImageData, 0, 3)) . ') in ImageCreateFromStringReplacement()');
             break;
     }
     if ($tempnam = tempnam($this->config_temp_directory, 'pThumb')) {
         if ($fp_tempnam = @fopen($tempnam, 'wb')) {
             fwrite($fp_tempnam, $RawImageData);
             fclose($fp_tempnam);
             if ($ICFSreplacementFunctionName == 'ImageCreateFromGIF' && !function_exists($ICFSreplacementFunctionName)) {
                 // Need to create from GIF file, but ImageCreateFromGIF does not exist
                 if (@(include_once 'phpthumb.gif.php')) {
                     // gif_loadFileToGDimageResource() cannot read from raw data, write to file first
                     if ($tempfilename = tempnam($this->config_temp_directory, 'pThumb')) {
                         if ($fp_tempfile = @fopen($tempfilename, 'wb')) {
                             fwrite($fp_tempfile, $RawImageData);
                             fclose($fp_tempfile);
                             $gdimg_source = gif_loadFileToGDimageResource($tempfilename);
                             unlink($tempfilename);
                             return $gdimg_source;
                             break;
                         } else {
                             $ErrorMessage = 'Failed to open tempfile in ' . __FILE__ . ' on line ' . __LINE__;
                         }
                     } else {
                         $ErrorMessage = 'Failed to open generate tempfile name in ' . __FILE__ . ' on line ' . __LINE__;
                     }
                 } else {
                     $ErrorMessage = 'Failed to include required file "phpthumb.gif.php" in ' . __FILE__ . ' on line ' . __LINE__;
                 }
             } elseif (function_exists($ICFSreplacementFunctionName) && ($gdimg_source = $ICFSreplacementFunctionName($tempnam))) {
                 // great
                 unlink($tempnam);
                 return $gdimg_source;
             } else {
                 // GD functions not available
                 // 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);
                 exit;
             }
         } else {
             $ErrorMessage = 'Failed to fopen(' . $tempnam . ', "wb") in ' . __FILE__ . ' on line ' . __LINE__ . "\n" . 'You may need to set $PHPTHUMB_CONFIG[temp_directory] in phpthumb.config.php';
         }
         unlink($tempnam);
     } else {
         $ErrorMessage = 'Failed to generate tempnam() in ' . __FILE__ . ' on line ' . __LINE__ . "\n" . 'You may need to set $PHPTHUMB_CONFIG[temp_directory] in phpthumb.config.php';
     }
     if ($DieOnErrors && !empty($ErrorMessage)) {
         die($ErrorMessage);
     }
     return false;
 }
 function SafeURLread($url, &$error)
 {
     $error = '';
     $parsed_url = @parse_url($url);
     $rawData = phpthumb_functions::URLreadFsock(@$parsed_url['host'], @$parsed_url['path'], $errstr, true, @$parsed_url['port'] ? @$parsed_url['port'] : 80);
     $error .= 'Error: ' . $errstr . "\n" . $url;
     if ($rawData === false) {
         return false;
     } elseif ($rawData === null) {
         // fall through
     } else {
         return $rawData;
     }
     $BrokenURLfopenPHPversions = array('4.4.2');
     if (in_array(phpversion(), $BrokenURLfopenPHPversions)) {
         $error .= 'fopen(URL) broken in PHP v' . phpversion() . '; ';
     } elseif (@ini_get('allow_url_fopen')) {
         $rawData = '';
         ob_start();
         if ($fp = fopen($url, 'rb')) {
             do {
                 $buffer = fread($fp, 8192);
                 $rawData .= $buffer;
             } while (strlen($buffer) > 0);
             fclose($fp);
         } else {
             $error .= trim(strip_tags(ob_get_contents()));
         }
         ob_end_clean();
         if (!$error) {
             return $rawData;
         }
         $error .= '; "allow_url_fopen" enabled but returned no data; ';
     } else {
         $error .= '"allow_url_fopen" disabled; ';
     }
     if (function_exists('curl_version') && !phpthumb_functions::FunctionIsDisabled('curl_exec')) {
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_HEADER, false);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
         $rawData = curl_exec($ch);
         curl_close($ch);
         if (strlen($rawData) > 0) {
             return $rawData;
         }
         $error .= 'CURL available but returned no data; ';
     } else {
         $error .= 'CURL unavailable; ';
     }
     return false;
 }
Beispiel #8
0
 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;
 }
function RedirectToCachedFile()
{
    global $phpThumb, $PHPTHUMB_CONFIG;
    $nice_cachefile = str_replace($phpThumb->osslash, '/', $phpThumb->cache_filename);
    $nice_docroot = str_replace($phpThumb->osslash, '/', rtrim($PHPTHUMB_CONFIG['document_root'], '/\\'));
    $parsed_url = @parse_url(@$_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->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 (ereg('^' . 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]));
        }
        if (!@$PHPTHUMB_CONFIG['cache_force_passthru'] && ereg('^' . preg_quote($nice_docroot) . '(.*)$', $nice_cachefile, $matches)) {
            header('Location: ' . dirname($matches[1]) . '/' . urlencode(basename($matches[1])));
        } else {
            @readfile($phpThumb->cache_filename);
        }
        exit;
    }
    return true;
}
 function GD2BMPstring(&$gd_image)
 {
     $imageX = ImageSX($gd_image);
     $imageY = ImageSY($gd_image);
     $BMP = '';
     for ($y = $imageY - 1; $y >= 0; $y--) {
         $thisline = '';
         for ($x = 0; $x < $imageX; $x++) {
             $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
             $thisline .= chr($argb['blue']) . chr($argb['green']) . chr($argb['red']);
         }
         while (strlen($thisline) % 4) {
             $thisline .= "";
         }
         $BMP .= $thisline;
     }
     $bmpSize = strlen($BMP) + 14 + 40;
     // BITMAPFILEHEADER [14 bytes] - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_62uq.asp
     $BITMAPFILEHEADER = 'BM';
     // WORD    bfType;
     $BITMAPFILEHEADER .= phpthumb_functions::LittleEndian2String($bmpSize, 4);
     // DWORD   bfSize;
     $BITMAPFILEHEADER .= phpthumb_functions::LittleEndian2String(0, 2);
     // WORD    bfReserved1;
     $BITMAPFILEHEADER .= phpthumb_functions::LittleEndian2String(0, 2);
     // WORD    bfReserved2;
     $BITMAPFILEHEADER .= phpthumb_functions::LittleEndian2String(54, 4);
     // DWORD   bfOffBits;
     // BITMAPINFOHEADER - [40 bytes] http://msdn.microsoft.com/library/en-us/gdi/bitmaps_1rw2.asp
     $BITMAPINFOHEADER = phpthumb_functions::LittleEndian2String(40, 4);
     // DWORD  biSize;
     $BITMAPINFOHEADER .= phpthumb_functions::LittleEndian2String($imageX, 4);
     // LONG   biWidth;
     $BITMAPINFOHEADER .= phpthumb_functions::LittleEndian2String($imageY, 4);
     // LONG   biHeight;
     $BITMAPINFOHEADER .= phpthumb_functions::LittleEndian2String(1, 2);
     // WORD   biPlanes;
     $BITMAPINFOHEADER .= phpthumb_functions::LittleEndian2String(24, 2);
     // WORD   biBitCount;
     $BITMAPINFOHEADER .= phpthumb_functions::LittleEndian2String(0, 4);
     // DWORD  biCompression;
     $BITMAPINFOHEADER .= phpthumb_functions::LittleEndian2String(0, 4);
     // DWORD  biSizeImage;
     $BITMAPINFOHEADER .= phpthumb_functions::LittleEndian2String(2835, 4);
     // LONG   biXPelsPerMeter;
     $BITMAPINFOHEADER .= phpthumb_functions::LittleEndian2String(2835, 4);
     // LONG   biYPelsPerMeter;
     $BITMAPINFOHEADER .= phpthumb_functions::LittleEndian2String(0, 4);
     // DWORD  biClrUsed;
     $BITMAPINFOHEADER .= phpthumb_functions::LittleEndian2String(0, 4);
     // DWORD  biClrImportant;
     return $BITMAPFILEHEADER . $BITMAPINFOHEADER . $BMP;
 }
Beispiel #11
0
 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);
 }
}
////////////////////////////////////////////////////////////////
// check to see if file can be output from source with no processing or caching
$CanPassThroughDirectly = true;
$FilenameParameters = array('h', 'w', 'sx', 'sy', 'sw', 'sh', 'bw', 'brx', 'bry', 'bg', 'bgt', 'bc', 'usa', 'usr', 'ust', 'wmf', 'wmp', 'wmm', 'wma', 'xto', 'ra', 'ar', 'iar', 'maxb');
foreach ($FilenameParameters as $key) {
    if (isset($_REQUEST[$key])) {
        $CanPassThroughDirectly = false;
        break;
    }
}
if ($CanPassThroughDirectly && !empty($_REQUEST['src'])) {
    // no parameters set, passthru
    $SourceFilename = $phpThumb->ResolveFilenameToAbsolute($_REQUEST['src']);
    if ($getimagesize = @GetImageSize($SourceFilename)) {
        header('Content-type: ' . phpthumb_functions::ImageTypeToMIMEtype($getimagesize[2]));
        @readfile($SourceFilename);
        exit;
    }
}
// check to see if file already exists in cache, and output it with no processing if it does
if (!empty($phpThumb->config_cache_directory) && empty($_REQUEST['phpThumbDebug'])) {
    $cache_filename = $phpThumb->GenerateCachedFilename();
    if (is_file($cache_filename)) {
        header('Content-type: image/' . $phpThumb->thumbnailFormat);
        @readfile($cache_filename);
        exit;
    }
}
////////////////////////////////////////////////////////////////
// You may want to pull data from a database rather than a physical file
Beispiel #13
0
 public function scanMusicFileTags()
 {
     # TODO: handle orphaned records
     # TODO: displaying itemsChecked / itemsProcessed is incorrect
     # TODO: which speed-calculation makes sense? itemsChecked/minutute or itemsProcessed/minute or both?
     $this->jobPhase = 2;
     $this->beginJob(array('msg' => 'collecting tracks to scan from mysql database'), __FUNCTION__);
     $app = \Slim\Slim::getInstance();
     $phpThumb = Bitmap::getPhpThumb();
     $phpThumb->setParameter('config_cache_directory', APP_ROOT . 'embedded');
     $getID3 = new \getID3();
     // make sure that a single directory will not be scanned twice
     $scannedDirectories = array();
     // get timestamps of all images from mysql database
     $imageTimestampsMysql = array();
     ////////////////////////////////////////////////////////////////
     // TEMP reset database status for testing purposes
     #$query = "UPDATE rawtagdata SET importStatus=1, lastScan=0;";
     #$app->db->query($query);
     #$query = "DELETE FROM bitmap WHERE trackId > 0;";
     #$app->db->query($query);
     ////////////////////////////////////////////////////////////////
     if ($app->config['images']['look_cover_directory'] == TRUE) {
         $this->pluralizeCommonArtworkDirectoryNames($app->config['images']['common_artwork_dir_names']);
     }
     $query = "\n\t\t\tSELECT COUNT(*) AS itemCountTotal\n\t\t\tFROM rawtagdata WHERE lastScan < filemtime";
     $this->itemCountTotal = (int) $app->db->query($query)->fetch_assoc()['itemCountTotal'];
     $query = "\n\t\t\tSELECT id,\n\t\t\t\trelativePath, relativePathHash, filemtime,\n\t\t\t\trelativeDirectoryPath, relativeDirectoryPathHash, directoryMtime \n\t\t\tFROM rawtagdata \n\t\t\tWHERE lastScan < filemtime";
     // LIMIT 200000,1000;";
     $result = $app->db->query($query);
     $extractedImages = 0;
     while ($record = $result->fetch_assoc()) {
         $this->itemCountChecked++;
         cliLog($record['id'] . ' ' . $record['relativePath'], 2);
         $this->updateJob(array('msg' => 'processed ' . $this->itemCountChecked . ' files', 'currentItem' => $record['relativePath'], 'extractedImages' => $extractedImages));
         $t = new Rawtagdata();
         $t->setId($record['id']);
         $t->setLastScan(time());
         $t->setImportStatus(2);
         // TODO: handle not found files
         if (is_file($app->config['mpd']['musicdir'] . $record['relativePath']) === TRUE) {
             $t->setFilesize(filesize($app->config['mpd']['musicdir'] . $record['relativePath']));
         } else {
             $t->setError('invalid file');
             $t->update();
             continue;
         }
         // skip very large files
         // TODO: how to handle this?
         if ($t->getFilesize() > 1000000000) {
             $t->setError('invalid filesize ' . $t->getFilesize() . ' bytes');
             $t->update();
             continue;
         }
         $tagData = $getID3->analyze($app->config['mpd']['musicdir'] . $record['relativePath']);
         \getid3_lib::CopyTagsToComments($tagData);
         $this->mapTagsToRawtagdataInstance($t, $tagData);
         $t->update();
         if (!$app->config['images']['read_embedded']) {
             continue;
         }
         if (isset($tagData['comments']['picture']) === FALSE) {
             continue;
         }
         if (is_array($tagData['comments']['picture']) === FALSE) {
             continue;
         }
         // loop through all embedded images
         foreach ($tagData['comments']['picture'] as $bitmapIndex => $bitmapData) {
             if (isset($bitmapData['image_mime']) === FALSE) {
                 // skip unspecifyable datachunk
                 continue;
             }
             if (isset($bitmapData['data']) === FALSE) {
                 // skip missing datachunk
                 continue;
             }
             $rawImageData = $bitmapData['data'];
             if (strlen($rawImageData) < 20) {
                 // skip obviously invalid imagedata
                 continue;
             }
             if (strlen($rawImageData) > 40000) {
                 // skip huge imagedata
                 // got errormessage "Maximum supported image dimension is 65500 pixels" from ???
                 continue;
             }
             # TODO: delete tmp files of php thumb - shouldn't phpThumb handle that itself?
             $phpThumb->resetObject();
             $phpThumb->setSourceData($rawImageData);
             $phpThumb->setParameter('config_cache_prefix', $record['relativePathHash'] . '_' . $bitmapIndex . '_');
             $phpThumb->SetCacheFilename();
             $phpThumb->GenerateThumbnail();
             \phpthumb_functions::EnsureDirectoryExists(dirname($phpThumb->cache_filename));
             $phpThumb->RenderToFile($phpThumb->cache_filename);
             $extractedImages++;
             if (is_file($phpThumb->cache_filename) === FALSE) {
                 // there had been an error
                 // TODO: how to handle this?
                 continue;
             }
             # TODO: general handling of permissions of created directories and files
             chmod($phpThumb->cache_filename, 0777);
             $relativePath = str_replace(APP_ROOT, '', $phpThumb->cache_filename);
             $relativePathHash = getFilePathHash($relativePath);
             $imageSize = GetImageSize($phpThumb->cache_filename);
             $bitmap = new Bitmap();
             $bitmap->setRelativePath($relativePath);
             $bitmap->setRelativePathHash($relativePathHash);
             $bitmap->setFilemtime(filemtime($phpThumb->cache_filename));
             $bitmap->setFilesize(filesize($phpThumb->cache_filename));
             $bitmap->setRawTagDataId($record['id']);
             # TODO: is there any more need for both ID's?
             $bitmap->setTrackId($record['id']);
             # TODO: is there any more need for both ID's?
             $bitmap->setEmbedded(1);
             // setAlbumId() will be applied later because at this time we havn't any albumId's but tons of bitmap-record-dupes
             if ($imageSize !== FALSE) {
                 $bitmap->setWidth($imageSize[0]);
                 $bitmap->setHeight($imageSize[1]);
                 $bitmap->setMimeType($imageSize['mime']);
             } else {
                 $bitmap->setError(1);
             }
             # TODO: can we call insert() immediatly instead of letting check the update() function itself?
             # this could save performance...
             $bitmap->update();
         }
     }
     $this->finishJob(array('extractedImages' => $extractedImages), __FUNCTION__);
     return;
 }
 function exif_info()
 {
     static $exif_info = array();
     if (empty($exif_info)) {
         // based on code by johnschaefer at gmx dot de
         // from PHP help on gd_info()
         $exif_info = array('EXIF Support' => '', 'EXIF Version' => '', 'Supported EXIF Version' => '', 'Supported filetypes' => '');
         $phpinfo_array = phpthumb_functions::phpinfo_array();
         foreach ($phpinfo_array as $line) {
             $line = trim(strip_tags($line));
             foreach ($exif_info as $key => $value) {
                 if (strpos($line, $key) === 0) {
                     $newvalue = trim(str_replace($key, '', $line));
                     $exif_info[$key] = $newvalue;
                 }
             }
         }
     }
     return $exif_info;
 }
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;
}
 function getGD_PixelPlotterVersion()
 {
     if (!$this->m_bLoaded) {
         return false;
     }
     // PREPARE COLOR TABLE (RGBQUADs)
     if ($this->m_img->m_gih->m_bLocalClr) {
         $pal = $this->m_img->m_gih->m_colorTable->toString();
     } elseif ($this->m_gfh->m_bGlobalClr) {
         $pal = $this->m_gfh->m_colorTable->toString();
     } else {
         die('No color table available in getGD_PixelPlotterVersion()');
     }
     $PlottingIMG = ImageCreate($this->m_gfh->m_nWidth, $this->m_gfh->m_nHeight);
     $NumColorsInPal = floor(strlen($pal) / 3);
     for ($i = 0; $i < $NumColorsInPal; $i++) {
         $ThisImageColor[$i] = ImageColorAllocate($PlottingIMG, ord($pal[$i * 3 + 0]), ord($pal[$i * 3 + 1]), ord($pal[$i * 3 + 2]));
     }
     // PREPARE BITMAP BITS
     $data = $this->m_img->m_data;
     $nPxl = ($this->m_gfh->m_nHeight - 1) * $this->m_gfh->m_nWidth;
     for ($y = 0; $y < $this->m_gfh->m_nHeight; $y++) {
         if (!phpthumb_functions::FunctionIsDisabled('set_time_limit')) {
             set_time_limit(30);
         }
         for ($x = 0; $x < $this->m_gfh->m_nWidth; $x++, $nPxl++) {
             if ($x >= $this->m_img->m_gih->m_nLeft && $y >= $this->m_img->m_gih->m_nTop && $x < $this->m_img->m_gih->m_nLeft + $this->m_img->m_gih->m_nWidth && $y < $this->m_img->m_gih->m_nTop + $this->m_img->m_gih->m_nHeight) {
                 // PART OF IMAGE
                 if (@$this->m_img->m_bTrans && ord($data[$nPxl]) == $this->m_img->m_nTrans) {
                     ImageSetPixel($PlottingIMG, $x, $this->m_gfh->m_nHeight - $y - 1, $ThisImageColor[$this->m_gfh->m_nBgColor]);
                 } else {
                     ImageSetPixel($PlottingIMG, $x, $this->m_gfh->m_nHeight - $y - 1, $ThisImageColor[ord($data[$nPxl])]);
                 }
             } else {
                 // BACKGROUND
                 ImageSetPixel($PlottingIMG, $x, $this->m_gfh->m_nHeight - $y - 1, $ThisImageColor[$this->m_gfh->m_nBgColor]);
             }
         }
         $nPxl -= $this->m_gfh->m_nWidth << 1;
     }
     return $PlottingIMG;
 }
Beispiel #17
0
 function SafeURLread($url, &$error, $timeout = 10, $followredirects = true)
 {
     $error = '';
     $parsed_url = @parse_url($url);
     $alreadyLookedAtURLs[trim($url)] = true;
     do {
         $rawData = phpthumb_functions::URLreadFsock(@$parsed_url['host'], @$parsed_url['path'] . '?' . @$parsed_url['query'], $errstr, true, @$parsed_url['port'] ? @$parsed_url['port'] : 80, $timeout);
         if (eregi('302 Found; Location\\: (http.*)', $errstr, $matches)) {
             $matches[1] = trim(@$matches[1]);
             if ($alreadyLookedAtURLs[$matches[1]]) {
                 break;
             }
             $alreadyLookedAtURLs[$matches[1]] = true;
             $parsed_url = @parse_url($matches[1]);
         } else {
             break;
         }
     } while (true);
     $error .= 'Error opening "' . $url . '":' . "\n\n" . $errstr;
     if ($rawData === false) {
         return false;
     } elseif ($rawData === null) {
         // fall through
     } else {
         return $rawData;
     }
     if (function_exists('curl_version') && !phpthumb_functions::FunctionIsDisabled('curl_exec')) {
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_HEADER, false);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
         curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
         $rawData = curl_exec($ch);
         curl_close($ch);
         if (strlen($rawData) > 0) {
             return $rawData;
         }
         $error .= 'CURL available but returned no data; ';
     } else {
         $error .= 'CURL unavailable; ';
     }
     $BrokenURLfopenPHPversions = array('4.4.2');
     if (in_array(phpversion(), $BrokenURLfopenPHPversions)) {
         $error .= 'fopen(URL) broken in PHP v' . phpversion() . '; ';
     } elseif (@ini_get('allow_url_fopen')) {
         $rawData = '';
         ob_start();
         if ($fp = fopen($url, 'rb')) {
             do {
                 $buffer = fread($fp, 8192);
                 $rawData .= $buffer;
             } while (strlen($buffer) > 0);
             fclose($fp);
         } else {
             $error .= trim(strip_tags(ob_get_contents()));
         }
         ob_end_clean();
         if (!$error) {
             return $rawData;
         }
         $error .= '; "allow_url_fopen" enabled but returned no data; ';
     } else {
         $error .= '"allow_url_fopen" disabled; ';
     }
     return false;
 }
    echo 'orange';
} elseif ($php_sapi_name == 'cgi') {
    echo 'yellow';
} elseif ($php_sapi_name == 'apache') {
    echo 'lime';
} else {
    echo 'green';
}
echo '">' . $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" bgcolor="';
$server_software = getenv('SERVER_SOFTWARE');
if (!$server_software) {
    echo 'red';
} elseif (eregi('^Apache/([0-9\\.]+)', $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" bgcolor="';
$curl_version = function_exists('curl_version') ? curl_version() : '';
if (is_array($curl_version)) {
    $curl_version = @$curl_version['version'];
}
if ($curl_version) {
 function applyUnsharpMask(&$img, $amount, $radius, $threshold)
 {
     // $img is an image that is already created within php using
     // imgcreatetruecolor. No url! $img must be a truecolor image.
     // Attempt to calibrate the parameters to Photoshop:
     $amount = min($amount, 500);
     $amount = $amount * 0.016;
     if ($amount == 0) {
         return true;
     }
     $radius = min($radius, 50);
     $radius = $radius * 2;
     $threshold = min($threshold, 255);
     $radius = abs(round($radius));
     // Only integers make sense.
     if ($radius == 0) {
         return true;
     }
     $w = ImageSX($img);
     $h = ImageSY($img);
     $imgCanvas = ImageCreateTrueColor($w, $h);
     $imgCanvas2 = ImageCreateTrueColor($w, $h);
     ImageCopy($imgCanvas, $img, 0, 0, 0, 0, $w, $h);
     ImageCopy($imgCanvas2, $img, 0, 0, 0, 0, $w, $h);
     $builtinFilterSucceeded = false;
     if ($radius == 1) {
         if (phpthumb_functions::version_compare_replacement(phpversion(), '5.0.0', '>=') && phpthumb_functions::gd_is_bundled()) {
             if (ImageFilter($imgCanvas, IMG_FILTER_GAUSSIAN_BLUR) && ImageFilter($imgCanvas2, IMG_FILTER_GAUSSIAN_BLUR)) {
                 $builtinFilterSucceeded = true;
             }
         }
     }
     if (!$builtinFilterSucceeded) {
         $imgBlur = ImageCreateTrueColor($w, $h);
         $imgBlur2 = ImageCreateTrueColor($w, $h);
         ///////////////////////////
         //
         // Gaussian blur matrix:
         //	1  2  1
         //	2  4  2
         //	1  2  1
         //
         ///////////////////////////
         // Move copies of the image around one pixel at the time and merge them with weight
         // according to the matrix. The same matrix is simply repeated for higher radii.
         for ($i = 0; $i < $radius; $i++) {
             ImageCopy($imgBlur, $imgCanvas, 0, 0, 1, 1, $w - 1, $h - 1);
             // up left
             ImageCopyMerge($imgBlur, $imgCanvas, 1, 1, 0, 0, $w, $h, 50);
             // down right
             ImageCopyMerge($imgBlur, $imgCanvas, 0, 1, 1, 0, $w - 1, $h, 33.33333);
             // down left
             ImageCopyMerge($imgBlur, $imgCanvas, 1, 0, 0, 1, $w, $h - 1, 25);
             // up right
             ImageCopyMerge($imgBlur, $imgCanvas, 0, 0, 1, 0, $w - 1, $h, 33.33333);
             // left
             ImageCopyMerge($imgBlur, $imgCanvas, 1, 0, 0, 0, $w, $h, 25);
             // right
             ImageCopyMerge($imgBlur, $imgCanvas, 0, 0, 0, 1, $w, $h - 1, 20);
             // up
             ImageCopyMerge($imgBlur, $imgCanvas, 0, 1, 0, 0, $w, $h, 16.666667);
             // down
             ImageCopyMerge($imgBlur, $imgCanvas, 0, 0, 0, 0, $w, $h, 50);
             // center
             ImageCopy($imgCanvas, $imgBlur, 0, 0, 0, 0, $w, $h);
             // During the loop above the blurred copy darkens, possibly due to a roundoff
             // error. Therefore the sharp picture has to go through the same loop to
             // produce a similar image for comparison. This is not a good thing, as processing
             // time increases heavily.
             ImageCopy($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h);
             ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 50);
             ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 33.33333);
             ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 25);
             ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 33.33333);
             ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 25);
             ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 20);
             ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 16.666667);
             ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 50);
             ImageCopy($imgCanvas2, $imgBlur2, 0, 0, 0, 0, $w, $h);
         }
         ImageDestroy($imgBlur);
         ImageDestroy($imgBlur2);
     }
     // Calculate the difference between the blurred pixels and the original
     // and set the pixels
     for ($x = 0; $x < $w; $x++) {
         // each row
         for ($y = 0; $y < $h; $y++) {
             // each pixel
             $rgbOrig = ImageColorAt($imgCanvas2, $x, $y);
             $rOrig = $rgbOrig >> 16 & 0xff;
             $gOrig = $rgbOrig >> 8 & 0xff;
             $bOrig = $rgbOrig & 0xff;
             $rgbBlur = ImageColorAt($imgCanvas, $x, $y);
             $rBlur = $rgbBlur >> 16 & 0xff;
             $gBlur = $rgbBlur >> 8 & 0xff;
             $bBlur = $rgbBlur & 0xff;
             // When the masked pixels differ less from the original
             // than the threshold specifies, they are set to their original value.
             $rNew = abs($rOrig - $rBlur) >= $threshold ? max(0, min(255, $amount * ($rOrig - $rBlur) + $rOrig)) : $rOrig;
             $gNew = abs($gOrig - $gBlur) >= $threshold ? max(0, min(255, $amount * ($gOrig - $gBlur) + $gOrig)) : $gOrig;
             $bNew = abs($bOrig - $bBlur) >= $threshold ? max(0, min(255, $amount * ($bOrig - $bBlur) + $bOrig)) : $bOrig;
             if ($rOrig != $rNew || $gOrig != $gNew || $bOrig != $bNew) {
                 $pixCol = ImageColorAllocate($img, $rNew, $gNew, $bNew);
                 ImageSetPixel($img, $x, $y, $pixCol);
             }
         }
     }
     ImageDestroy($imgCanvas);
     ImageDestroy($imgCanvas2);
     return true;
 }
 function filedate_remote($remotefile, $timeout = 10)
 {
     $date = false;
     $url = parse_url($remotefile);
     if ($fp = @fsockopen($url['host'], $url['port'] ? $url['port'] : 80, $errno, $errstr, $timeout)) {
         fwrite($fp, 'HEAD ' . @$url['path'] . @$url['query'] . ' HTTP/1.0' . "\r\n" . 'Host: ' . @$url['host'] . "\r\n\r\n");
         if (phpthumb_functions::version_compare_replacement(phpversion(), '4.3.0', '>=')) {
             stream_set_timeout($fp, $timeout);
         }
         while (!feof($fp)) {
             $headerline = fgets($fp, 4096);
             if (eregi('^Last-Modified: (.*)', $headerline, $matches)) {
                 $date = strtotime($matches[1]) - date('Z');
                 break;
             }
         }
         fclose($fp);
     }
     return $date;
 }
 function ResolveFilenameToAbsolute($filename)
 {
     if (empty($filename)) {
         return false;
     }
     if (preg_match('#^[a-z0-9]+\\:/{1,2}#i', $filename)) {
         // eg: http://host/path/file.jpg (HTTP URL)
         // eg: ftp://host/path/file.jpg  (FTP URL)
         // eg: data1:/path/file.jpg      (Netware path)
         //$AbsoluteFilename = $filename;
         return $filename;
     } elseif ($this->iswindows && isset($filename[1]) && $filename[1] == ':') {
         // absolute pathname (Windows)
         $AbsoluteFilename = $filename;
     } elseif ($this->iswindows && (substr($filename, 0, 2) == '//' || substr($filename, 0, 2) == '\\\\')) {
         // absolute pathname (Windows)
         $AbsoluteFilename = $filename;
     } elseif ($filename[0] == '/') {
         if (@is_readable($filename) && !@is_readable($this->config_document_root . $filename)) {
             // absolute filename (*nix)
             $AbsoluteFilename = $filename;
         } elseif (isset($filename[1]) && $filename[1] == '~') {
             // /~user/path
             if ($ApacheLookupURIarray = phpthumb_functions::ApacheLookupURIarray($filename)) {
                 $AbsoluteFilename = $ApacheLookupURIarray['filename'];
             } else {
                 $AbsoluteFilename = realpath($filename);
                 if (@is_readable($AbsoluteFilename)) {
                     $this->DebugMessage('phpthumb_functions::ApacheLookupURIarray() failed for "' . $filename . '", but the correct filename (' . $AbsoluteFilename . ') seems to have been resolved with realpath($filename)', __FILE__, __LINE__);
                 } elseif (is_dir(dirname($AbsoluteFilename))) {
                     $this->DebugMessage('phpthumb_functions::ApacheLookupURIarray() failed for "' . dirname($filename) . '", but the correct directory (' . dirname($AbsoluteFilename) . ') seems to have been resolved with realpath(.)', __FILE__, __LINE__);
                 } else {
                     return $this->ErrorImage('phpthumb_functions::ApacheLookupURIarray() failed for "' . $filename . '". This has been known to fail on Apache2 - try using the absolute filename for the source image (ex: "/home/user/httpdocs/image.jpg" instead of "/~user/image.jpg")');
                 }
             }
         } else {
             // relative filename (any OS)
             if (preg_match('#^' . preg_quote($this->config_document_root) . '#', $filename)) {
                 $AbsoluteFilename = $filename;
                 $this->DebugMessage('ResolveFilenameToAbsolute() NOT prepending $this->config_document_root (' . $this->config_document_root . ') to $filename (' . $filename . ') resulting in ($AbsoluteFilename = "' . $AbsoluteFilename . '")', __FILE__, __LINE__);
             } else {
                 $AbsoluteFilename = $this->config_document_root . $filename;
                 $this->DebugMessage('ResolveFilenameToAbsolute() prepending $this->config_document_root (' . $this->config_document_root . ') to $filename (' . $filename . ') resulting in ($AbsoluteFilename = "' . $AbsoluteFilename . '")', __FILE__, __LINE__);
             }
         }
     } else {
         // relative to current directory (any OS)
         $AbsoluteFilename = $this->config_document_root . preg_replace('#[/\\\\]#', DIRECTORY_SEPARATOR, dirname(@$_SERVER['PHP_SELF'])) . DIRECTORY_SEPARATOR . preg_replace('#[/\\\\]#', DIRECTORY_SEPARATOR, $filename);
         //			$AbsoluteFilename = dirname(__FILE__).DIRECTORY_SEPARATOR.preg_replace('#[/\\\\]#', DIRECTORY_SEPARATOR, $filename);
         $AbsoluteFilename = preg_replace('~[\\/]+~', DIRECTORY_SEPARATOR, $AbsoluteFilename);
         //if (!@file_exists($AbsoluteFilename) && @file_exists(realpath($this->DotPadRelativeDirectoryPath($filename)))) {
         //	$AbsoluteFilename = realpath($this->DotPadRelativeDirectoryPath($filename));
         //}
         if (substr(dirname(@$_SERVER['PHP_SELF']), 0, 2) == '/~') {
             if ($ApacheLookupURIarray = phpthumb_functions::ApacheLookupURIarray(dirname(@$_SERVER['PHP_SELF']))) {
                 $AbsoluteFilename = $ApacheLookupURIarray['filename'] . DIRECTORY_SEPARATOR . $filename;
             } else {
                 $AbsoluteFilename = realpath('.') . DIRECTORY_SEPARATOR . $filename;
                 if (@is_readable($AbsoluteFilename)) {
                     $this->DebugMessage('phpthumb_functions::ApacheLookupURIarray() failed for "' . dirname(@$_SERVER['PHP_SELF']) . '", but the correct filename (' . $AbsoluteFilename . ') seems to have been resolved with realpath(.)/$filename', __FILE__, __LINE__);
                 } elseif (is_dir(dirname($AbsoluteFilename))) {
                     $this->DebugMessage('phpthumb_functions::ApacheLookupURIarray() failed for "' . dirname(@$_SERVER['PHP_SELF']) . '", but the correct directory (' . dirname($AbsoluteFilename) . ') seems to have been resolved with realpath(.)', __FILE__, __LINE__);
                 } else {
                     return $this->ErrorImage('phpthumb_functions::ApacheLookupURIarray() failed for "' . dirname(@$_SERVER['PHP_SELF']) . '". This has been known to fail on Apache2 - try using the absolute filename for the source image');
                 }
             }
         }
     }
     if (is_link($AbsoluteFilename)) {
         $this->DebugMessage('is_link()==true, changing "' . $AbsoluteFilename . '" to "' . readlink($AbsoluteFilename) . '"', __FILE__, __LINE__);
         $AbsoluteFilename = readlink($AbsoluteFilename);
     }
     if (realpath($AbsoluteFilename)) {
         $AbsoluteFilename = realpath($AbsoluteFilename);
     }
     if ($this->iswindows) {
         $AbsoluteFilename = preg_replace('#^' . preg_quote(realpath($this->config_document_root)) . '#i', realpath($this->config_document_root), $AbsoluteFilename);
         $AbsoluteFilename = str_replace(DIRECTORY_SEPARATOR, '/', $AbsoluteFilename);
     }
     if (!$this->config_allow_src_above_docroot && !preg_match('#^' . preg_quote(str_replace(DIRECTORY_SEPARATOR, '/', realpath($this->config_document_root))) . '#', $AbsoluteFilename)) {
         $this->DebugMessage('!$this->config_allow_src_above_docroot therefore setting "' . $AbsoluteFilename . '" (outside "' . realpath($this->config_document_root) . '") to null', __FILE__, __LINE__);
         return false;
     }
     if (!$this->config_allow_src_above_phpthumb && !preg_match('#^' . preg_quote(str_replace(DIRECTORY_SEPARATOR, '/', dirname(__FILE__))) . '#', $AbsoluteFilename)) {
         $this->DebugMessage('!$this->config_allow_src_above_phpthumb therefore setting "' . $AbsoluteFilename . '" (outside "' . dirname(__FILE__) . '") to null', __FILE__, __LINE__);
         return false;
     }
     return $AbsoluteFilename;
 }
 function WatermarkOverlay(&$gdimg_dest, &$img_watermark, $alignment = '*', $opacity = 50, $margin = 5)
 {
     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));
         if ($margin < 1) {
             $watermark_margin_percent = 1 - $margin;
         } else {
             $watermark_margin_percent = (100 - max(0, min(100, $margin))) / 100;
         }
         $watermark_margin_x = round((1 - $watermark_margin_percent) * $img_source_width);
         $watermark_margin_y = round((1 - $watermark_margin_percent) * $img_source_height);
         switch ($alignment) {
             case '*':
                 if ($gdimg_tiledwatermark = phpthumb_functions::ImageCreateFunction($img_source_width, $img_source_height)) {
                     ImageAlphaBlending($gdimg_tiledwatermark, false);
                     if (phpthumb_functions::version_compare_replacement(phpversion(), '4.3.2', '>=')) {
                         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 += round($watermark_source_width + (1 - $watermark_margin_percent) * $img_source_width)) {
                         for ($y = $watermark_margin_y; $y < $img_source_height + $watermark_source_height; $y += round($watermark_source_height + (1 - $watermark_margin_percent) * $img_source_height)) {
                             ImageCopy($gdimg_tiledwatermark, $img_watermark, $x, $y, 0, 0, min($watermark_source_width, $img_source_width - $x - (1 - $watermark_margin_percent) * $img_source_width), min($watermark_source_height, $img_source_height - $y - (1 - $watermark_margin_percent) * $img_source_height));
                         }
                     }
                     $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 = round(($img_source_height - $watermark_source_height) * $watermark_margin_percent);
                 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 = round(($img_source_width - $watermark_source_width) * $watermark_margin_percent);
                 $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 = round(($img_source_width - $watermark_source_width) * $watermark_margin_percent);
                 $watermark_destination_y = $watermark_margin_y;
                 break;
             case 'BL':
                 $watermark_destination_x = $watermark_margin_x;
                 $watermark_destination_y = round(($img_source_height - $watermark_source_height) * $watermark_margin_percent);
                 break;
             case 'BR':
             default:
                 $watermark_destination_x = round(($img_source_width - $watermark_source_width) * $watermark_margin_percent);
                 $watermark_destination_y = round(($img_source_height - $watermark_source_height) * $watermark_margin_percent);
                 break;
         }
         ImageAlphaBlending($gdimg_dest, false);
         if (phpthumb_functions::version_compare_replacement(phpversion(), '4.3.2', '>=')) {
             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 SanitizeFilename($filename)
 {
     $filename = ereg_replace('[^' . preg_quote(' !#$%^()+,-.;<>=@[]_{}') . 'a-zA-Z0-9]', '_', $filename);
     if (phpthumb_functions::version_compare_replacement(phpversion(), '4.1.0', '>=')) {
         $filename = trim($filename, '.');
     }
     return $filename;
 }
$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;
 public function SendSaveAsFileHeaderIfNeeded() {
     if (headers_sent()) {
         return false;
     }
     $downloadfilename = phpthumb_functions::SanitizeFilename(@$_GET['sia'] ? $_GET['sia'] : (@$_GET['down'] ? $_GET['down'] : 'phpThumb_generated_thumbnail'.(@$_GET['f'] ? $_GET['f'] : 'jpg')));
     if (@$downloadfilename) {
         $this->DebugMessage('SendSaveAsFileHeaderIfNeeded() sending header: Content-Disposition: '.(@$_GET['down'] ? 'attachment' : 'inline').'; filename="'.$downloadfilename.'"', __FILE__, __LINE__);
         header('Content-Disposition: '.(@$_GET['down'] ? 'attachment' : 'inline').'; filename="'.$downloadfilename.'"');
     }
     return true;
 }
<?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>
Beispiel #27
0
 public 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 gd_info()
 {
     if (function_exists('gd_info')) {
         // built into PHP v4.3.0+ (with bundled GD2 library)
         return gd_info();
     }
     static $gd_info = array();
     if (empty($gd_info)) {
         // based on code by johnschaefer at gmx dot de
         // from PHP help on gd_info()
         $gd_info = array('GD Version' => '', 'FreeType Support' => false, 'FreeType Linkage' => '', 'T1Lib Support' => false, 'GIF Read Support' => false, 'GIF Create Support' => false, 'JPG Support' => false, 'PNG Support' => false, 'WBMP Support' => false, 'XBM Support' => false);
         $phpinfo_array = phpthumb_functions::phpinfo_array();
         foreach ($phpinfo_array as $line) {
             $line = trim(strip_tags($line));
             foreach ($gd_info as $key => $value) {
                 //if (strpos($line, $key) !== false) {
                 if (strpos($line, $key) === 0) {
                     $newvalue = trim(str_replace($key, '', $line));
                     $gd_info[$key] = $newvalue;
                 }
             }
         }
         if (empty($gd_info['GD Version'])) {
             // probable cause: "phpinfo() disabled for security reasons"
             if (function_exists('ImageTypes')) {
                 $imagetypes = ImageTypes();
                 if ($imagetypes & IMG_PNG) {
                     $gd_info['PNG Support'] = true;
                 }
                 if ($imagetypes & IMG_GIF) {
                     $gd_info['GIF Create Support'] = true;
                 }
                 if ($imagetypes & IMG_JPG) {
                     $gd_info['JPG Support'] = true;
                 }
                 if ($imagetypes & IMG_WBMP) {
                     $gd_info['WBMP Support'] = true;
                 }
             }
             // to determine capability of GIF creation, try to use ImageCreateFromGIF on a 1px GIF
             if (function_exists('ImageCreateFromGIF')) {
                 if ($tempfilename = $this->phpThumb_tempnam()) {
                     if ($fp_tempfile = @fopen($tempfilename, 'wb')) {
                         fwrite($fp_tempfile, base64_decode('R0lGODlhAQABAIAAAH//AP///ywAAAAAAQABAAACAUQAOw=='));
                         // very simple 1px GIF file base64-encoded as string
                         fclose($fp_tempfile);
                         // if we can convert the GIF file to a GD image then GIF create support must be enabled, otherwise it's not
                         $gd_info['GIF Read Support'] = (bool) @ImageCreateFromGIF($tempfilename);
                     }
                     unlink($tempfilename);
                 }
             }
             if (function_exists('ImageCreateTrueColor') && @ImageCreateTrueColor(1, 1)) {
                 $gd_info['GD Version'] = '2.0.1 or higher (assumed)';
             } elseif (function_exists('ImageCreate') && @ImageCreate(1, 1)) {
                 $gd_info['GD Version'] = '1.6.0 or higher (assumed)';
             }
         }
     }
     return $gd_info;
 }
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>
Beispiel #30
0
 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;
 }