Page 1 of 1

Watermarking an Image

Posted: Thu Jan 10, 2013 3:16 pm
by SonOfDiablo
Hello fellers! :)

I'm new on the forum but I wanted to ask about something :)

I'm trying to make a watermark on an image I have med with php

Like this:
<?php
 $im = ImageCreate(500,100);
 $white = ImageColorAllocate($im,0xFF,0xFF,0xFF);
 $black = ImageColorAllocate($im,0x00,0x00,0x00);
 $color = ImageColorAllocate($im,57,57,57);
 $red = ImageColorAllocate($im,250,0,0);
 $num = rand(1,3);
 ImageFilledRectangle($im,0,0,500,100,$color);
 ImageRectangle($im, 0, 0, 499, 99, $red);
 ImageRectangle($im, 4, 4, 495, 95, $red);
 //$rep = ImageCreateFromJPEG("http://i48.tinypic.com/w6xssz.jpg");
 //$thanks = ImageCreateFromPNG("http://i.minus.com/ijp06izjgIy7G.png");

 
 
 
 if($num == 1){
	ImageString($im, 5, 100, 30, 'If I helped you in any way please', $red);
	ImageString($im, 5, 110, 50, 'Click "Thankyou" and/or +rep me :)', $red);
 }else if($num == 2){
	ImageString($im, 5, 90, 30, 'Please click "Thankyou" and/or +rep me :)', $red);
	ImageString($im, 5, 110, 50, 'If I have helped you in any way!', $red);
 }else if($num == 3){
	ImageString($im, 5, 90, 30, 'Just Because You Come From A Bad Place', $red);
	ImageString($im, 5, 92, 50, 'Does Not Mean You Can\'t Do Good Things', $red);
	ImageString($im, 5, 165, 70, 'I Just Choose Not To', $red);}
 header('Content-Type: image/png');
 ImagePNG($im);
?>
I have watched the tutorials from: http://www.youtube.com/user/betterphp on the subject but I can't figure out how to do it anyways :(

And the watermark need to be a linked image from another site :)

Can someone on here please help me with this?

many thanks! :D

Re: Watermarking an Image

Posted: Thu Jan 10, 2013 7:55 pm
by jacek
ImageCreateFromPNG("http://i.minus.com/ijp06izjgIy7G.png")
Should work as far as I know. Could you describe the specific problem you are having ?

Re: Watermarking an Image

Posted: Thu Jan 10, 2013 9:11 pm
by SonOfDiablo
Sure :)

I have made the picture above but when I try to use
imagecopy($main, $overlay, 0, 0, 0, 0, imagesx($overlay), imagesy($overlay));
(where $main is the pic I have made and $overlay is a pic I have linked)

It won't show the picture it just shows as a broken picture :/

Re: Watermarking an Image

Posted: Fri Jan 11, 2013 4:46 pm
by ExtremeGaming
The php functions imagesx(); and imagesy(); needs an image source to work such as one from imagecreatetruecolor(); I assume you are using a link.

For more information you can check out
imagesx() and imagesy() or even getimagesize(); although that would require a bit more work in getting height and width