[ad_1]
Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –
Beginner PHP Tutorial – 163 – Watermarking Images Part 3
by
Tags:
Comments
15 responses to “Beginner PHP Tutorial – 163 – Watermarking Images Part 3”
-
here is a working source:
<?php
header ('Content-type: image/jpeg');
if(isset($_GET['source'])){
$source = $_GET['source'];$watermark = ImageCreateFromPng('logo.png');
$watermark_w = ImageSx($watermark);
$watermark_h = ImageSy($watermark);$image = ImageCreateTrueColor($watermark_w,$watermark_h);
$image = ImageCreateFromJpeg($source);$image_size = GetImageSize($source);
$x = $image_size[0] – $watermark_w – 50;
$y = $image_size[1] – $watermark_h – 10;ImageCopyMerge($image, $watermark, $x, $y, 0, 0, $watermark_w, $watermark_h, 100);
ImageJpeg($image);
}
?> -
for transparent watermarks try:
imagealphablending($image,true);
imagesavealpha($image,true);
imagecopy($image,$watermark,$x,$y,0,0,$watermark_width,$watermark_height);
instead of:
imagecopymerge($image,$watermark,$x,$y,0,0,$watermark_width,$watermark_height,50);however, the opacity effect does not work then…
-
I get a small page-like icon upper right corner, instead of my image and watermark? Any clues why, please help…thank you!
-
I only watched the video, but I was thinking the same Zeryab. The second declaration of $image overwrites the first one, so the first declaration ($image = imagecreatetruecolor($watermark_width, $watermark_height)) doesn't do anything anymore. So my guess is you can just leave it out.
-
What is the purpose of this line can anybody please tell me
$image = imagecreatetruecolor($watermark_width , $watermark_height);My code is running perfectly without this too
-
For some reason i cannot use properly GD library, i cannot use jpeg, nor png files, i have typed the code correctly, and i am only getting error messages, i really need help, if anyone wants to explain to me how to create watermarking, step by step, please answer me. I am using Wamp, and PHP 5.5.12, the latest version for Windows 8.1
-
For some reason, I have the exact same code but jpg files don't work. I had to use png files for all of the pictures and functions.
-
Don't merge with a .png that has transparent background, the picture gets messed up.
-
if you could make video that explaines how working this last part,but correctly working that doesn't work on your video,i mean on those last 2 minutes,when generate new pic with watermark.
-
need a little help!!!
getimagesize() is not working in my case (i am using WAMP )
it returns 0 as height and width.
php manual says that
"Some formats may contain no image or may contain multiple images. In these cases, getimagesize() might not be able to properly determine the image size. getimagesize() will return zero for width and height in these cases. " -
If it doesn't work even xampp is installed, check your speelings in your script maybe that's the problem like mine 🙂
-
"$image=imagecreatetruecolor(……, …..)"
this is not required….
anyway thanks for the tutorial.. -
thanx
-
you should have exploded the filename and removed the extension before saving it so its hone.watermarked.jpg not phone.jpg.watermarked.jpg huh? 😛 none the less good vid 🙂
-
Haha, good finding…haha Thanks alex.
Leave a Reply