Jump to content

Splash marks on images?


hlstriker

Recommended Posts

Hi, I did exactly what that first tutorial said and thousands of symbols display on my page instead of the image. I don't get any errors or warnings, just thousands of symbols. Here is the code I used... (note I had to put another header after the image was created otherwise nothing would display on my page.)

 

header('content-type: image/jpeg');

$watermark = imagecreatefrompng('watermark.png');
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
$image = imagecreatefromjpeg("path/to/image");
$size = getimagesize("path/to/image");
$dest_x = $size[0] - $watermark_width - 5;
$dest_y = $size[1] - $watermark_height - 5;
imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100);
imagejpeg($image);
imagedestroy($image);
imagedestroy($watermark);

header('content-type: text/html');

echo "<img src='$image'>";

 

example link of a dear water marked dead friend.

http://www.freelanceprogrammers.co.uk/font/

 

dont need all that code here you go

 

<?php 
$im    = imagecreatefrompng("mat_picture.png");
$yellow = ImageColorAllocate ($im, 235, 235, 51);
$saying="hi there i am redarrow"; 
ImageTTFText ($im, 15, 1, 25, 70, $yellow, "/WINDOWS/Fonts/IMPACT.ttf", "$saying"); 
ImagePNG($im); 
?> 

Put image code in a file of its own

 

:: wm_image.php ::

<?php

$image = $_GET['image'];

$watermark = imagecreatefrompng('watermark.png');
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
$image = imagecreatefromjpeg($image);
$size = getimagesize($image);
$dest_x = $size[0] - $watermark_width - 5;
$dest_y = $size[1] - $watermark_height - 5;
imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100);

header('content-type: image/jpeg');
imagejpeg($image);
imagedestroy($image);
imagedestroy($watermark);
?>

 

in another file, place image on page

 

:: another.php ::

<?php

echo '<img src="wm_image.php?image=path/to/image">';

?>

~redarrow,

 

Apart from missing content-type header, and if you only want a text-only watermark at the top left, it looks fine.

 

The extra (uneccessary, as you say) code as posted is to place an image as a watermark relative to the bottom right of an image

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.