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!
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. =)
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.
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.
<?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){
$codeїr] = hexdec(substr($hex, 0 ,2));
$codeїg] = hexdec(substr($hex, 2 ,2));
$codeїb] = hexdec(substr($hex, 4 ,2));
return $code;
} // 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їr], $codeїg], $codeї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"){
Header( "Content-type: image/jpeg");
ImageJPEG($backgroundimage);
}
else{
Header( "Content-type: image/png");
ImagePNG($backgroundimage);
}
// destroy the memory
ImageDestroy($backgroundimage);
ImageDestroy($image_id);
?>