PHP/GD – transparent background

imagecolortransparent is probably not what you want here if you’re merging images, as single-colour transparency is nasty. Instead, try it with a transparent fill mask like so: <?php $image = imagecreatetruecolor(100, 100); // Transparent Background imagealphablending($image, false); $transparency = imagecolorallocatealpha($image, 0, 0, 0, 127); imagefill($image, 0, 0, $transparency); imagesavealpha($image, true); // Drawing over $black = … Read more

PHP allocate color without image resource

16711680 (decimal) is 0x00FF0000 (hexadecimal) 00 – Alpha value (0 dec) FF – Red (255 dec) 00 – Green (0 dec) 00 – Blue (0 dec) See http://www.php.net/manual/en/function.imagecolorallocatealpha.php to set the alpha byte Edit: Also, to answer your first question — yes, you can create a color without an image resource (and, consequently without a … Read more

Merge two images in php

The best approach for this situation may be to create a new image in memory with the combined dimensions you desire, then copy or resample the existing images to the new image, and then save the new image to disk. For example: function merge($filename_x, $filename_y, $filename_result) { // Get dimensions for specified images list($width_x, $height_x) … Read more

Merge two PNG images with PHP GD library

$image1 = imagecreatefrompng(‘a.png’); //300 x 300 $image2 = imagecreatefrompng(‘b.png’); //150 x 150 imagecopymerge($image1, $image2, 0, 0, 75, 75, 150, 150, 50); this should be all you need. $image1 should hold the merged image where image2 has been overlayed with 50% opacity. the last argument is the alpha of the merged copy. http://php.net/manual/en/function.imagecopymerge.php

Can I detect animated gifs using php and gd?

While searching for a solution to the same problem I noticed that the php.net site has a follow-up to the code Davide and Kris are referring to, but, according to the author, less memory-intensive, and possibly less disk-intensive. I’ll replicate it here, because it may be of interest. source: http://www.php.net/manual/en/function.imagecreatefromgif.php#88005 function is_ani($filename) { if(!($fh = … Read more

PHP – Replace colour within image

You need to open the input file and scan each pixel to check for your chromokey value. Something like this: // Open input and output image $src = imagecreatefromJPEG(‘input.jpg’) or die(‘Problem with source’); $out = ImageCreateTrueColor(imagesx($src),imagesy($src)) or die(‘Problem In Creating image’); // scan image pixels for ($x = 0; $x < imagesx($src); $x++) { for … Read more

Working with GD ( imagettftext() ) and UTF-8 characters

As I continued my research I came up with an answer for my problem, this piece of code did it! private function properText($text){ $text = mb_convert_encoding($text, “HTML-ENTITIES”, “UTF-8”); $text = preg_replace(‘~^(&([a-zA-Z0-9]);)~’,htmlentities(‘${1}’),$text); return($text); } Now all the characters (and all the new ones I’ve seen) that troubled me are displayed correctly!

PHP/GD : Better Gaussian blur

After coming across the same problem, I applied the same filter a few times, and each time to the resulting resource of the previous “imagefilter” call. I got the ‘more blurry’ effect you’re looking for. e.g.: for ($x=1; $x<=15; $x++) imagefilter($image, IMG_FILTER_GAUSSIAN_BLUR);

Cropping image in PHP

You could use imagecopy to crop a required part of an image. The command goes like this: imagecopy ( resource $dst_im – the image object , resource $src_im – destination image , int $dst_x – x coordinate in the destination image (use 0) , int $dst_y – y coordinate in the destination image (use 0) … Read more