Watermarking an Image

Ask about a PHP problem here.
Post Reply
SonOfDiablo
Posts: 2
Joined: Thu Jan 10, 2013 3:09 pm

Watermarking an Image

Post 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:
[syntax=php]<?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);
?>[/syntax]

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
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Watermarking an Image

Post by jacek »

[syntax=php]ImageCreateFromPNG("http://i.minus.com/ijp06izjgIy7G.png")[/syntax]
Should work as far as I know. Could you describe the specific problem you are having ?
Image
SonOfDiablo
Posts: 2
Joined: Thu Jan 10, 2013 3:09 pm

Re: Watermarking an Image

Post by SonOfDiablo »

Sure :)

I have made the picture above but when I try to use
[syntax=php]imagecopy($main, $overlay, 0, 0, 0, 0, imagesx($overlay), imagesy($overlay));[/syntax]

(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 :/
ExtremeGaming
Posts: 205
Joined: Mon Jul 09, 2012 11:13 pm

Re: Watermarking an Image

Post 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
<?php while(!$succeed = try()); ?>
Post Reply