adding (c) image to bottom of another image

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
macewan
Forum Commoner
Posts: 97
Joined: Mon Jul 07, 2003 8:27 pm

adding (c) image to bottom of another image

Post by macewan »

What am interested in doing is adding a small "copyright notice image" to the bottom of images that are being displayed. In the example below - the black and white image would be image 'bob.jpg' and the red image with the standard white text would be image 'fred.jpg'.

bob.jpg and fred.jpg are combined to create the image known as example.jpg

The reason I want to overlay pictures with a standard copyright image instead of just adding text to the image is that it, well, I just want to do it that way. =)

any suggestions? pointers?

Image
qartis
Forum Contributor
Posts: 271
Joined: Sat Dec 14, 2002 4:43 pm
Location: BC, Canada
Contact:

Post by qartis »

You can't just draw a red box, and put the text on top of it?
User avatar
cactus
Forum Regular
Posts: 343
Joined: Tue Jun 10, 2003 4:16 am
Location: UK

Post by cactus »

You want to have a look at the image processing methods provided by the GD libs, dependant on your version of PHP you may already have these installed.

Ref : XL. Image functions
http://www.php.net/manual/en/ref.image.php

With these functions you can overlay text/color etc on a background image, which is esentially what you are trying to do.

Regards,
qartis
Forum Contributor
Posts: 271
Joined: Sat Dec 14, 2002 4:43 pm
Location: BC, Canada
Contact:

Post by qartis »

The reason I want to overlay pictures with a standard copyright image instead of just adding text to the image is that it, well, I just want to do it that way. =)
It sounds like he knows how to do text, he just wants do to it with an image instead. Maybe he wants to get a graphic (C) sign, with a little background image, or something? Not sure.
macewan
Forum Commoner
Posts: 97
Joined: Mon Jul 07, 2003 8:27 pm

Post by macewan »

I want to lay 'fred.jpg' on top of every an image when needed.

http://www.deadmule.com/macewan/screens ... p/fred.jpg
macewan
Forum Commoner
Posts: 97
Joined: Mon Jul 07, 2003 8:27 pm

Post by macewan »

thanks to everyone for the suggestions. this is what i will be using.

http://www.php.net/manual/en/function.i ... ymerge.php

*thanks cactus for the link*
macewan
Forum Commoner
Posts: 97
Joined: Mon Jul 07, 2003 8:27 pm

Post by macewan »

http://www.deadmule.com/macewan/testing/

=)


click test.php


*shesh. the hosting company is moving servers so here's the code*

Code: Select all

<?php
$im = "copyright.png";
// $bg = "ffddee";     // hex representation of the color (i.e. #ffffff for white)
$out = "jpg";       // or "jpg" for jpg file output
$backgroundfile = "back.jpg";  // optional backgroundfile if you don't want to use a color

//
// function to convert hex colorcode to decimal
//

function colordecode($hex)&#123;

  $code&#1111;r] = hexdec(substr($hex, 0 ,2));
  $code&#1111;g] = hexdec(substr($hex, 2 ,2));
  $code&#1111;b] = hexdec(substr($hex, 4 ,2));

  return $code;

&#125; // end func colordecode

// create the resource id
$image_id = imageCreateFromPNG($im);

// get image size
$im_X = ImageSX($image_id);
$im_Y = ImageSY($image_id);

// create a truecolor background image of the right size
// or use a background image like this
$backgroundimage = imageCreateFromJPEG($backgroundfile);
//$backgroundimage = imagecreatetruecolor($im_X, $im_Y);

// get the desired backgroundcolor:
// don't use this if you want to use a background image
// $code = colordecode($bg);
// $backgroundcolor = ImageColorAllocate($backgroundimage, $code&#1111;r], $code&#1111;g], $code&#1111;b]);
// ImageFilledRectangle($backgroundimage, 0, 0, $im_X, $im_Y, $backgroundcolor);

// merge the two together with alphablending on!
ImageAlphaBlending($backgroundimage, true);
imagecopy($backgroundimage, $image_id, 0, 0, 0, 0, $im_X, $im_Y);

// output the image:
if($output == "jpg")&#123;
 Header( "Content-type: image/jpeg");
  ImageJPEG($backgroundimage);
  &#125;
  else&#123;
      Header( "Content-type: image/png");
      ImagePNG($backgroundimage);
      &#125;

// destroy the memory
ImageDestroy($backgroundimage);
ImageDestroy($image_id);
?>
Post Reply