As an additional note, i found another watermark script which fails with the 
same error (it will need the same .htaccess as in my first post - save the 
script as modify.php as well or adjust the name in .htaccess accordingly) as 
PHP will try to parse the jpg file instead of displaying the image.

Again, switching to cgi-fcgi or mod_php, the image gets displayed 
(differences between mod_fcgid and mod_cgi as shown in the httpd.include in 
my previous post):

---
<?php
// -------------------------------------------------------------------------  
//
// The code below is free software; you can redistribute it and/or modify 
//
// it under the terms of the Creative Commons Attribution license: 
//
// http://creativecommons.org/licenses/by/2.5/ 
//
// The following line must reside in any derivative works: 
//
// portions (cc) Doncho Angelov 2005 (http://doncho.net) 
//
// -------------------------------------------------------------------------  
//

//
// SETUP
//

// the location of the picture, which contains the normal watermark
//  (we first try to apply this one)
define(BIG_WATERMARK_FILE, $_SERVER['DOCUMENT_ROOT'] . "/watermark.jpg");
// the location of the picture, which contains the smaller watermark
//  (for the images, which are smaller than 5 times the normal watermark)
define(SMALL_WATERMARK_FILE, $_SERVER['DOCUMENT_ROOT'] . "/watermark.jpg");

// SETUP ends

// generate the image with watermark
function watermark($source, $outputType="") {

  // determine the type of the source image
  $sourceType = getFileType($source);

  // output the header of the new image
  if (empty($outputType)) $outputType = $sourceType;
  // if you hate GIF files, you can switch to PNG
  if ($outputType == "gif") $outputType = "png";
  header("Content-type:image/$outputType");

  // create the source
  $createSource = "ImageCreateFrom".strtoupper($sourceType);
  $showImage = "Image".strtoupper($outputType);
  $output = $createSource($source);

  // load the big logo
  $logo = loadWatermark(BIG_WATERMARK_FILE);

  // check if the watermark is not bigger than the logo
  if (ImageSX($output)<(ImageSX($logo)*5) || 
ImageSY($output)<(ImageSY($logo)*5))
    // if so, fallback to a smaller logo
    $logo = loadWatermark(SMALL_WATERMARK_FILE);

  $x = ImageSX($output) - ImageSX($logo);
  $y = ImageSY($output) - ImageSY($logo);

  ImageAlphaBlending($output, true);

  ImageCopy($output, $logo, $x, $y, 0, 0, ImageSX($logo), ImageSY($logo));
  $showImage($output);

  ImageDestroy($output);
  ImageDestroy($logo);
}

function getFileType($string)
{
  $type = strtolower(eregi_replace("^(.*\.)","",$string));
  if ($type == "jpg") $type = "jpeg";

  return $type;
}

function loadWatermark($watermarkFile)
{
  $watermarkType = getFileType($watermarkFile);
  $createWatermark = "ImageCreateFrom".strtoupper($watermarkType);
  return $createWatermark($watermarkFile);
}

//
// main functionality starts here
//

$image = $_SERVER["PATH_TRANSLATED"];

if (empty($image)) die();

if (!file_exists($image))
{
  header("404 Not Found");
  echo "Requested File Not Found."; die();
}

$outputType = getFileType($image);

watermark($image, $outputType);
?>
---

I wonder whether i have a special environment which causes this behaviour 
only with me. Otherwise i would expect a lot more 'noise' from other people 
when switching to mod_fcgid from either mod_php or mod_fastcgi as these 
scripts will fail.

Regards,
Marcus



Reply via email to