Results 1 to 8 of 8
  1. #1

    Watermark function won't work after PHP upgrade

    Hey guys,

    The following script worked when I was using a version of WAMP (Windows Apache MySQL PHP) that had Apache 2.2.8 and PHP 5.2.6 - the current WAMP that I had to install is Apache 2.2.11 and PHP 5.3.0. Now I've noticed my watermark function no longer works. I've been able to confirm that GD support does exist ( http://mifbody.com/test.php ) but yet the images appear broken if they use the below watermark function. Any ideas?

    PHP Code:
    <?php

    $watermark 
    "watermark.png";
    $image $_SERVER["PATH_TRANSLATED"];


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

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

    /************
    ** if(isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER']))
    ** {
    **    if($_SERVER['HTTP_REFERER'] == $_SERVER['HTTP_HOST'])
    **    {
    **        no_watermark($image, $outputType);
    **    }
    **    else {
    **         watermark($image, $watermark, $outputType);
    **    }
    ** }
    ** else {
    **    no_watermark($image, $outputType);
    ** }
    ************/

    watermark($image$watermark$outputType);
    $outputType getFileType($image);




    /**
       Outputs the image $source with $watermark in the lower right corner.
       @param $source the source image
       @param $watermark the watermark to apply
       @param $outputType the type to output as (png, jpg, gif, etc.)
                          defaults to the image type of $source if left blank
    */
    function watermark($source$watermark$outputType="") {
       
    $sourceType getFileType($source);
       
    $watermarkType getFileType($watermark);

       if (empty(
    $outputType)) $outputType $sourceType;
       
    header("Content-type:image/$outputType");

       
    // Derive function names
       
    $createSource "ImageCreateFrom".strtoupper($sourceType);
       
    $showImage "Image".strtoupper($outputType);
       
    $createWatermark "ImageCreateFrom".strtoupper($watermarkType);

       
    // Load original and watermark to memory
       
    $output $createSource($source);
       
    $logo $createWatermark($watermark);
       
    ImageAlphaBlending($outputtrue);

       
    // Find proper coordinates so watermark will be in the lower right corner
       
    $x ImageSX($output) - ImageSX($logo);
       
    $y ImageSY($output) - ImageSY($logo);

       
    // Display
       
    ImageCopy($output$logo$x/2$y/200ImageSX($logo), ImageSY($logo));
       
    $showImage($output);

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

    function 
    no_watermark($source$outputType="") {
       
    $sourceType getFileType($source);

       if (empty(
    $outputType)) $outputType $sourceType;
       
    header("Content-type:image/$outputType");

       
    $createSource "ImageCreateFrom".strtoupper($sourceType);
       
    $showImage "Image".strtoupper($outputType);
       
    $output $createSource($source);


       
    $showImage($output);

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


    function 
    getFileType($string) {
       
    $type strtolower(eregi_replace("^(.*)\.","",$string));
       if (
    $type == "jpg"$type "jpeg";
       return 
    $type;
    }
    ?>
    Windows 2008 R2 SP1 x64
    Core2Quad Q9650; 8GB ddr2

  2. #2
    Join Date
    Jun 2006
    Location
    Tewksbury, MA
    Posts
    221
    Hello,

    You can give this a try, not sure if it'll work or not. I made some changes though.

    PHP Code:
    <?php

    $watermark 
    "watermark.png";
    $image $_SERVER["PATH_TRANSLATED"];


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

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

    /************
    ** if(isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER']))
    ** {
    **    if($_SERVER['HTTP_REFERER'] == $_SERVER['HTTP_HOST'])
    **    {
    **        no_watermark($image, $outputType);
    **    }
    **    else {
    **         watermark($image, $watermark, $outputType);
    **    }
    ** }
    ** else {
    **    no_watermark($image, $outputType);
    ** }
    ************/

    watermark($image$watermark$outputType);

    $outputType getFileType($image);



    /**
       Outputs the image $source with $watermark in the lower right corner.
       @param $source the source image
       @param $watermark the watermark to apply
       @param $outputType the type to output as (png, jpg, gif, etc.)
                          defaults to the image type of $source if left blank
    */
    function watermark($source$watermark$outputType="") {
       
    $sourceType getFileType($source);
       
    $watermarkType getFileType($watermark);

       if (empty(
    $outputType)) $outputType $sourceType;
       
    header("Content-type:image/$outputType");

       
    // Derive function names
       
    $createSource "ImageCreateFrom".strtoupper($sourceType);
       
    $showImage "Image".strtoupper($outputType);
       
    $createWatermark "ImageCreateFrom".strtoupper($watermarkType);

       
    // Load original and watermark to memory
       
    $output call_user_func($createSource$source);
       
    $logo call_user_func($createWatermark$watermark);
       
    ImageAlphaBlending($outputtrue);

       
    // Find proper coordinates so watermark will be in the lower right corner
       
    $x ImageSX($output) - ImageSX($logo);
       
    $y ImageSY($output) - ImageSY($logo);

       
    // Display
       
    ImageCopy($output$logo$x/2$y/200ImageSX($logo), ImageSY($logo));
       
    call_user_func($showImage$output);

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

    function 
    no_watermark($source$outputType="") {
       
    $sourceType getFileType($source);

       if (empty(
    $outputType)) $outputType $sourceType;
       
    header("Content-type:image/$outputType");

       
    $createSource "ImageCreateFrom".strtoupper($sourceType);
       
    $showImage "Image".strtoupper($outputType);
       
    $output call_user_func($createSource$source);


       
    call_user_func($showImage$output);

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


    function 
    getFileType($string) {
       
    $type strtolower(eregi_replace("^(.*)\.","",$string));
       if (
    $type == "jpg"$type "jpeg";
       return 
    $type;
    }
    ?>
    Brandon Long | https://brandonlong.me/
    Just a guy with a brain.

  3. #3
    Join Date
    Nov 2001
    Location
    The South
    Posts
    5,403
    Do you get any errors? Check your error_log (depends on how your system is setup where this would be and even what it's named). Sometimes running a script interactively on the command line from a shell can shed some light as well.
    Gary Harris - the artist formerly known as Dixiesys
    resident grumpy redneck

  4. #4
    Thanks for the help! Unfortunately it still displays a broken image:
    http://mifbody.com/dtcs/DTC%20029.jpg
    Windows 2008 R2 SP1 x64
    Core2Quad Q9650; 8GB ddr2

  5. #5
    Quote Originally Posted by 2Grumpy View Post
    Do you get any errors? Check your error_log (depends on how your system is setup where this would be and even what it's named). Sometimes running a script interactively on the command line from a shell can shed some light as well.
    D'oh - should have checked that first.

    Here's what I see in the apache error log:

    [Mon Aug 31 09:55:03 2009] [error] [client 206.57.42.130] PHP Notice: Undefined variable: outputType in C:\\wamp\\www\\mifbody\\watermark\\watermark.php on line 30
    [Mon Aug 31 09:55:03 2009] [error] [client 206.57.42.130] PHP Deprecated: Function eregi_replace() is deprecated in C:\\wamp\\www\\mifbody\\watermark\\watermark.php on line 93
    [Mon Aug 31 09:55:03 2009] [error] [client 206.57.42.130] PHP Deprecated: Function eregi_replace() is deprecated in C:\\wamp\\www\\mifbody\\watermark\\watermark.php on line 93
    [Mon Aug 31 09:55:04 2009] [error] [client 206.57.42.130] PHP Deprecated: Function eregi_replace() is deprecated in C:\\wamp\\www\\mifbody\\watermark\\watermark.php on line 93
    [Mon Aug 31 09:56:16 2009] [error] [client 173.76.164.53] PHP Notice: Undefined variable: outputType in C:\\wamp\\www\\mifbody\\watermark\\watermark.php on line 30, referer: http://www.webhostingtalk.com/showthread.php?p=6366440
    [Mon Aug 31 09:56:16 2009] [error] [client 173.76.164.53] PHP Deprecated: Function eregi_replace() is deprecated in C:\\wamp\\www\\mifbody\\watermark\\watermark.php on line 93, referer: http://www.webhostingtalk.com/showthread.php?p=6366440
    [Mon Aug 31 09:56:16 2009] [error] [client 173.76.164.53] PHP Deprecated: Function eregi_replace() is deprecated in C:\\wamp\\www\\mifbody\\watermark\\watermark.php on line 93, referer: http://www.webhostingtalk.com/showthread.php?p=6366440
    [Mon Aug 31 09:56:17 2009] [error] [client 173.76.164.53] PHP Deprecated: Function eregi_replace() is deprecated in C:\\wamp\\www\\mifbody\\watermark\\watermark.php on line 93, referer: http://www.webhostingtalk.com/showthread.php?p=6366440
    Windows 2008 R2 SP1 x64
    Core2Quad Q9650; 8GB ddr2

  6. #6
    I fixed the first error message about $OutputType being unrecognized (put it before the watermark() call.

    It looks like eregi is not compatible with PHP 5.3.0. Anyone know how to convert that to preg_replace?
    Windows 2008 R2 SP1 x64
    Core2Quad Q9650; 8GB ddr2

  7. #7
    Join Date
    May 2009
    Posts
    766
    PHP Code:
    $type strtolower(eregi_replace("^(.*)\.","",$string)); 
    Well, for starters, you never needed eregi_replace() in here...ereg_replace would have worked just fine.

    You're not doing anything in the Regular Expression itself that isn't PCRE-compatible, so just wrap your pattern in delimiters and you should be set:

    PHP Code:
    $type strtolower(preg_replace("/^(.*)\./"""$string)); //untested! 
    Of course this demonstrates Perl's never-ending superiority over PHP.

    PHP Code:
    perl -'$string="filename.PNG";$type = $string =~ s/^.*\.(.+)$/\L$1\E/;print "$string\n";'
    png 

  8. #8
    That worked perfectly - thank you!!!!
    Windows 2008 R2 SP1 x64
    Core2Quad Q9650; 8GB ddr2

Similar Threads

  1. php virtual() function doesn't work
    By sytker in forum Hosting Security and Technology
    Replies: 5
    Last Post: 05-30-2009, 08:44 AM
  2. PHP mail() function does not work
    By tlsuess in forum Hosting Security and Technology
    Replies: 2
    Last Post: 07-26-2007, 08:10 AM
  3. [php] Why does my function not work?
    By ic3d in forum Programming Discussion
    Replies: 15
    Last Post: 11-28-2006, 07:43 AM
  4. WaterMark Source, Watermark you images for free
    By elsonar in forum Other Offers & Requests
    Replies: 7
    Last Post: 06-13-2006, 05:32 PM
  5. mail() php function doesn't work...
    By webdirect in forum Hosting Security and Technology
    Replies: 5
    Last Post: 05-14-2005, 12:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •