Trouble displaying watermarked image

+1 Dan Howell · March 28, 2015
Trouble with PHP exercise 163 watermarking on an image - created code mirroring tutorial, but the output is a mini page-icon instead of my image. Any ideas, please help.

Post a Reply

Replies

Oldest  Newest  Rating
+2 Çağlan Turgut · March 30, 2015
What did you write? Can you please give the exact code that doesn't work? Also did you try running it on a different PHP version?
+1 Dan Howell · March 30, 2015
Hi, thanks for the reply! I have coded 2 files total (should actually be mirror image of Alex's php tutorial 161-163)

1st file:
<?php

/*
watermarking images
C:\xampp\htdocs\xampp\img\watermarkchurch.jpg
C:\xampp\htdocs\xampp\img\watermarklogo.png
*/

header('Content-type: image/jpeg');
 
if (isset($_GET['source']))
{    
    $source = $_GET['source'];
    
    $watermark = $imagecreatefrompng('bpt161-watermarklogo.png');
     //    ('C:\xampp\htdocs\img\bpt161-watermarklogo.png');      
    $watermark_width = imagesx($watermark);
    $watermark_height = imagesy($watermark);
    
    $image = $imagecreatetruecolor
            ($watermark_width, $watermark_height);
    $image = $imagecreatefromjpeg($source);
    
    $image_size = getimagesize($source);   
    $x = $image_size[0] - $watermark_width - 10;
    $y = $image_size[1] - $watermark_height - 10;     

    imagecopymerge($image, $watermark, $x, $y, 0, 0,
            $watermark_width, $watermark_height, 20);
    
    imagejpeg($image); 
}
?>
   

2nd file which I run:
<img src="bpt161-watermarkgeneration.php?source=bpt161-watermarkchurch.jpg" />
+1 Dan Howell · April 1, 2015
Hey Ça?lan Turgut, I found the answer. Its funny but sometimes you just don't think of the obvious answer. But, I added too many $'s:

$watermark = $imagecreatefrompng('bpt161-watermarklogo.png');
$image = $imagecreatetruecolor
($watermark_width, $watermark_height);
$image = $imagecreatefromjpeg($source);
Thank you for your concern!
0 Çağlan Turgut · April 1, 2015
Oh, I'm glad you found it. Yeah, dollar signs are sometimes hard to detect.
  • 1

PHP

106,928 followers
About

Server-side, HTML embedded scripting language used to create dynamic Web pages.

Links
Moderators