[PHP] Creating watermarks

2007-08-04 Thread Tom Ray [Lists]
I've been learning how to use PHP with the GD Library and I've managed 
to learn quite a bit. I can upload, resize, create thumbnails and I'm 
even able to create security code images for forms. My question is how 
do I create a Watermark on the image? I want something transparent but 
still visible enough to see the copyright and the website. I want to put 
it in the center of the image. I would use a non-water marked image and 
when it's called on (depending on viewing size) I want the water mark to 
be added.


How would one go about doing that?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Creating watermarks

2007-08-04 Thread Greg Donald
On 8/4/07, Tom Ray [Lists] [EMAIL PROTECTED] wrote:
 I've been learning how to use PHP with the GD Library and I've managed
 to learn quite a bit. I can upload, resize, create thumbnails and I'm
 even able to create security code images for forms. My question is how

This is usually referred to as a captcha.

 do I create a Watermark on the image? I want something transparent but
 still visible enough to see the copyright and the website. I want to put
 it in the center of the image. I would use a non-water marked image and
 when it's called on (depending on viewing size) I want the water mark to
 be added.

 How would one go about doing that?

You can write words on images using imagettftext().


-- 
Greg Donald
http://destiney.com/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Creating watermarks

2007-08-04 Thread Jan Reiter
Hi!

Try using imagealphablending() to blend your logo onto the original image.
This function should not require the user browser to be capable of blending
functions as would using the alpha channel of a png inmage or such ... 

Jan


-Original Message-
From: Tom Ray [Lists] [mailto:[EMAIL PROTECTED] 
Sent: Saturday, August 04, 2007 5:32 PM
To: php-general@lists.php.net
Subject: [PHP] Creating watermarks

I've been learning how to use PHP with the GD Library and I've managed 
to learn quite a bit. I can upload, resize, create thumbnails and I'm 
even able to create security code images for forms. My question is how 
do I create a Watermark on the image? I want something transparent but 
still visible enough to see the copyright and the website. I want to put 
it in the center of the image. I would use a non-water marked image and 
when it's called on (depending on viewing size) I want the water mark to 
be added.

How would one go about doing that?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Creating watermarks

2007-08-04 Thread GP INTERACTIVE
you can use also the following function :

?php

  // --- image play path
  $watermarkfile = 'images/play_small.png'; // as an example

  function getPictureMarked($sourcefile, $watermarkfile) {

#
# $sourcefile = Filename of the picture to be watermarked.
# $watermarkfile = Filename of the 24-bit PNG watermark file.
#

//Get the resource ids of the pictures
$watermarkfile_id = imagecreatefrompng($watermarkfile);

imageAlphaBlending($watermarkfile_id, false);
imageSaveAlpha($watermarkfile_id, true);

$fileType = strtolower(substr($sourcefile, strlen($sourcefile)-3));

switch($fileType) {
case('gif'):
$sourcefile_id = imagecreatefromgif($sourcefile);
break;

case('png'):
$sourcefile_id = imagecreatefrompng($sourcefile);
break;

default:
$sourcefile_id = imagecreatefromjpeg($sourcefile);
}

//Get the sizes of both pix
$sourcefile_width=imageSX($sourcefile_id);
$sourcefile_height=imageSY($sourcefile_id);
$watermarkfile_width=imageSX($watermarkfile_id);
$watermarkfile_height=imageSY($watermarkfile_id);

$dest_x = ( $sourcefile_width / 2 ) - ( $watermarkfile_width / 2 );
$dest_y = ( $sourcefile_height / 2 ) - ( $watermarkfile_height / 2 );

// if a gif, we have to upsample it to a truecolor image
if($fileType == 'gif') {
// create an empty truecolor container
$tempimage = imagecreatetruecolor($sourcefile_width,
$sourcefile_height);

// copy the 8-bit gif into the truecolor image
imagecopy($tempimage, $sourcefile_id, 0, 0, 0, 0, $sourcefile_width,
$sourcefile_height);

// copy the source_id int
$sourcefile_id = $tempimage;
}

imagecopy($sourcefile_id, $watermarkfile_id, $dest_x, $dest_y, 0, 0,
$watermarkfile_width, $watermarkfile_height);

//Create a jpeg out of the modified picture
switch($fileType) {

// remember we don't need gif any more, so we use only png or jpeg.
// See the upsaple code immediately above to see how we handle gifs
case('png'):
header(Content-type: image/png);
imagepng ($sourcefile_id);
break;

default:
header(Content-type: image/jpg);
imagejpeg ($sourcefile_id);
}

imagedestroy($sourcefile_id);
imagedestroy($watermarkfile_id);

}
?

Regards,

Greg
http://www.psmdev.com


On 8/4/07, Tom Ray [Lists] [EMAIL PROTECTED] wrote:

 I've been learning how to use PHP with the GD Library and I've managed
 to learn quite a bit. I can upload, resize, create thumbnails and I'm
 even able to create security code images for forms. My question is how
 do I create a Watermark on the image? I want something transparent but
 still visible enough to see the copyright and the website. I want to put
 it in the center of the image. I would use a non-water marked image and
 when it's called on (depending on viewing size) I want the water mark to
 be added.

 How would one go about doing that?

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Creating watermarks

2007-08-04 Thread tedd

At 11:32 AM -0400 8/4/07, Tom Ray [Lists] wrote:
I've been learning how to use PHP with the GD Library and I've 
managed to learn quite a bit. I can upload, resize, create 
thumbnails and I'm even able to create security code images for 
forms. My question is how do I create a Watermark on the image? I 
want something transparent but still visible enough to see the 
copyright and the website. I want to put it in the center of the 
image. I would use a non-water marked image and when it's called on 
(depending on viewing size) I want the water mark to be added.


How would one go about doing that?


Tom:

I just combine images -- it's simple.

Here's an example:

http://www.webbytedd.com/b/watermark/

Refresh and the watermark position will move.

Here's the code (refreshing will shift the watermark around):

?php

$place = c;
$original=imagecreatefromjpeg(mydog.jpg);
$watermark=imagecreatefrompng(copyright.png);

$osx=imagesx($original);
$osy=imagesy($original);
$wsx=imagesx($watermark);
$wsy=imagesy($watermark);

$place = rand(1,5);
switch ($place)
{
case 1: //c:
	imagecopy($original, $watermark, ($osx-$wsx)/2, 
($osy-$wsy)/2, 0, 0, $wsx, $wsy);	//center  works

break;

case 2: //nw:
	imagecopy($original, $watermark,0, 0, 0, 0, $wsx, $wsy); // 
upper left works

break;

case 3: //sw:
	imagecopy($original, $watermark, 0, ($osy-$wsy), 0, 0, $wsx, 
$wsy); // lower right works

break;

case 4: //ne:
	imagecopy($original, $watermark, ($osx-$wsx), 0, 0, 0, $wsx, 
$wsy); // upper left works

break;

case 5: //se:
	imagecopy($original, $watermark, ($osx-$wsx), ($osy-$wsy), 0, 
0, $wsx, $wsy);	// lower right works

break;

}

imagepng($original, trans.png);

?

Cheers,

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Creating watermarks

2007-08-04 Thread Tom Ray [Lists]

GP INTERACTIVE wrote:

you can use also the following function :

?php

  // --- image play path
  $watermarkfile = 'images/play_small.png'; // as an example
   
  function getPictureMarked($sourcefile, $watermarkfile) {
 
#

# $sourcefile = Filename of the picture to be watermarked.
# $watermarkfile = Filename of the 24-bit PNG watermark file.
#
  
//Get the resource ids of the pictures

$watermarkfile_id = imagecreatefrompng($watermarkfi
le);
  
imageAlphaBlending($watermarkfile_id, false);

imageSaveAlpha($watermarkfile_id, true);

$fileType = strtolower(substr($sourcefile, strlen($sourcefile)-3));

switch($fileType) {
case('gif'):
$sourcefile_id = imagecreatefromgif($sourcefile);
break;
  
case('png'):

$sourcefile_id = imagecreatefrompng($sourcefile);
break;
  
default:

$sourcefile_id = imagecreatefromjpeg($sourcefile);
}

//Get the sizes of both pix 
$sourcefile_width=imageSX($sourcefile_id);

$sourcefile_height=imageSY($sourcefile_id);
$watermarkfile_width=imageSX($watermarkfile_id);
$watermarkfile_height=imageSY($watermarkfile_id);

$dest_x = ( $sourcefile_width / 2 ) - ( $watermarkfile_width / 2 );
$dest_y = ( $sourcefile_height / 2 ) - ( $watermarkfile_height / 2 );
  
// if a gif, we have to upsample it to a truecolor image

if($fileType == 'gif') {
// create an empty truecolor container
$tempimage = imagecreatetruecolor($sourcefile_width, 
$sourcefile_height);
  
// copy the 8-bit gif into the truecolor image
imagecopy($tempimage, $sourcefile_id, 0, 0, 0, 0, 
$sourcefile_width, $sourcefile_height);
  
// copy the source_id int

$sourcefile_id = $tempimage;
}

imagecopy($sourcefile_id, $watermarkfile_id, $dest_x, $dest_y, 0, 
0, $watermarkfile_width, $watermarkfile_height);


//Create a jpeg out of the modified picture
switch($fileType) {
  
// remember we don't need gif any more, so we use only png or 
jpeg.
// See the upsaple code immediately above to see how we handle 
gifs

case('png'):
header(Content-type: image/png);
imagepng ($sourcefile_id);
break;
  
default:

header(Content-type: image/jpg);
imagejpeg ($sourcefile_id);
} 
 
imagedestroy($sourcefile_id);

imagedestroy($watermarkfile_id);
  
}

?

Regards,

Greg
http://www.psmdev.com http://www.psmdev.com/



On 8/4/07, *Tom Ray [Lists]*  [EMAIL PROTECTED] 
mailto:[EMAIL PROTECTED] wrote:


I've been learning how to use PHP with the GD Library and I've
managed
to learn quite a bit. I can upload, resize, create thumbnails and I'm
even able to create security code images for forms. My question
is how
do I create a Watermark on the image? I want something transparent
but
still visible enough to see the copyright and the website. I want
to put
it in the center of the image. I would use a non-water marked
image and
when it's called on (depending on viewing size) I want the water
mark to
be added.

How would one go about doing that?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
http://www.php.net/unsub.php



I'll test this tonight...thanks!

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php