I'm new here on Stackoverflow.
I would very much like figure out if it's possible to make a specific color of an image transparent using a PHP script. And if it is, how to go about doing it.
Let's say this is the image of which the background color (green) has to be completely transparent: French Hotdog w/ green background
I've got absolutely no idea what a script like this would look like or even where to begin.
I imagine that you'd propably have to set the unwanted RGB color and then "scan" every single pixel in image to determine which pixels have to be transparent. But other than that I'm clueless.
Seriously hope someone here is able to help me out on this one.
demo : http://so.devilmaycode.it/php-how-to-make-a-green-area-background-in-an-image-transparent
first of all the image should be png cause jpeg don't support transparency then the code is like this:
<?php
$image = 'test.png';
$im = imagecreatefrompng($image);
//if you exactly know the RGB color indexes
//$rgb = imagecolorexact($im, 0, 0, 0);
//or keep the rgb color by position so at top 0 left 0
$rgb = imagecolorat($im, 0, 0);
imagecolortransparent($im, $rgb);
header("Content-type: image/png");
//display the image directly
imagepng($im);
// or save it
// imagepng($im, 'test-to-transparent.png');
imagedestroy($im);
?>
imagecolortransparent() will help you:
...
$yourColor = imagecolorallocate($im, 0, 0, 0);
imagecolortransparent($im, $yourColor);
...
Related
I have a very frustrating situation. I am using PHP GD for the first time, and it's been a bit of a rollercoaster relationship. Basically, I am trying to merge 2 images, a square one (with a height/width of x) onto a rectangle (with a width of x and a height of y).
The square needs to be centered vertically. But this isn't the issue - I've managed to position it correctly.
Whats happening is, my rectangle is white. My square has a white background, so when the images are merged, it should just look like my asset on a white rectangluar background.
When I merge the image though, GD is for some reason changing my background white rectangle to black - so you can see the white square in the middle, with black "bars" on top and bottom. Can anyone help?
Code is:
//create copy of original image to correct size
imagecopyresized($dst_image, $src_image, 0,0,0,0,$x_width,$x_height,$orig_img_x_width,$orig_img_x_height);
imagejpeg($dst_image, "resized_copy.jpg", 100);
$img = imagecreatetruecolor(1333, 2000);
$white = imagecolorallocate($img, 255, 255, 255);
imagefill ( $img, 0, 0, $white );
imagefilledrectangle($img,0,0,1333,2000, $white);
imagejpeg($img, "rectangle.jpg", 100);
//merge images
$dest2 = imagecreatefromjpeg("rectangle.jpg");
$src2 = imagecreatefromjpeg('resized_copy.jpg');
imagecopymerge($dest2, $src2, 0, 0, 0, -333.5, $x_width, $x_height, 100);
imagejpeg($dest2, "final_image.jpg", 100);
I've tried using imagecopy instead of imagecopymerge, but I get the same result. I'm sure there is a simple explanation, but I cant seem to find it trawling through the php manual.
I've read your question a few times but I'm not convinced I understand exactly what you are trying to achieve so I've made a few assumptions in producing the below code.
For the sake of simplicity I've created a 'square.jpg' test image file like so:
(Note that I've used small image sizes here so I can show them inline.)
// read in the square test image.
$square = imagecreatefromjpeg('square.jpg');
$square_x = imagesx($square); // 100px
$square_y = imagesy($square); // 100px
// create the rectangular image to merge with.
$rectangle = imagecreatetruecolor(100, 200);
$rectangle_x = imagesx($rectangle); // 100px
$rectangle_y = imagesy($rectangle); // 200px
// note that this isn't white, but rather a lovely shade of blue to better
// show the image on the white SO background!
$white = imagecolorallocate($rectangle, 128, 128, 255);
imagefill($rectangle, 0, 0, $white);
// merge the images.
imagecopymerge(
$rectangle,
$square,
0,
($rectangle_y / 2) - ($square_y / 2), // to vertically centre the square.
0,
0,
$square_x,
$square_y,
75 // Just to show the merge clearly; change back to 100 for your usage.
);
imagejpeg($rectangle, 'final_image.jpg', 100);
imagedestroy($rectangle);
imagedestroy($square);
This gives me the following image in final_image.jpg:
Edit 2:
SUCCESS! many thanks to moycakes!
The correct way to convert a PNG to a GIF while retaining transparency goes as follows:
$input = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAXwAAAEYCAYAAABfgk2GAAAemklEQVR4Xu2dzYsm13WHe7rHxGATtw1Zu8UMY0wIkv6AoF44ZOEspFWyUytkkRASJG0sgS2NPkCKF5qxMSSboNbOu4xJcAxZaJRNlhqRVYaZpPUPSC2wiYmm38k5rS75delW1b1V9+Pcuk9BMR/vrXvPfc6p33veU7eqLu2wQQACEIBAEwQuNTFLJgkBCEAAAjsIPkEAAQhAoBECCH4jjmaaEIAABBB8YgACEIBAIwQQ/EYczTQhAAEIIPjEAAQgAIFGCCD4jTia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CHwCLphCAAARqJoDg1+w9bIcABCAQQADBD4BFUwhAAAI1E0Dwa/YetkMAAhAIIIDgB8CiKQQgAIGaCSD4NXsP2yEAAQgEEEDwA2DRFAIQgEDNBBD8mr2H7RCAAAQCCCD4AbBoCgEIQKBmAgh+zd7DdghAAAIBBBD8AFg0hQAEIFAzAQS/Zu9hOwQgAIEAAgh+ACyaQgACEKiZAIJfs/ewHQIQgEAAAQQ/ABZNIQABCNRMAMGv2XvYDgEIQCCAAIIfAIumEIAABGomgODX7D1shwAEIBBAAMEPgEVTCEAAAjUTQPBr9h62QwACEAgggOAHwKIpBCAAgZoJIPg1ew/bIQABCAQQQPADYNEUAhCAQM0EEPyavYftEIAABAIIIPgBsGgKAQhAoGYCCH7N3sN2CEAAAgEEEPwAWDSFAAQgUDMBBL9m72E7BCAAgQACCH4ALJpCAAIQqJkAgl+z97AdAhCAQAABBD8AFk0hAAEI1Ezg/wFm7lJkZahzkgAAAABJRU5ErkJggg==";
$image = imagecreatefrompng($input);
imagesavealpha($image, true);
imagecolortransparent($image, 127<<24);
imagegif($image, 'img/test.gif');
GOSH! two days for such a simple few lines of code >__<
Thank you to everyone who posted a suggestion.
old post:
Alright, I'm at my wits end now. (Why is the GD library in PHP so confusing??)
I've been at this for several hours two days now.. and I just can't get PHP to make a GIF from a PNG with a transparent background.
There are several posts about this on StackOverflow but none of the solutions provided really helped me at all. I always end up with either a black background image or everything black in my image becomes transparent except for the background (or just everything stays black).
I've typed imagecolorallocate and imagecolortransparent so many times that these commands have lost their meaning to me.. >___<
my code looks like this:
$input = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAXwAAAEYCAYAAABfgk2GAAAemklEQVR4Xu2dzYsm13WHe7rHxGATtw1Zu8UMY0wIkv6AoF44ZOEspFWyUytkkRASJG0sgS2NPkCKF5qxMSSboNbOu4xJcAxZaJRNlhqRVYaZpPUPSC2wiYmm38k5rS75delW1b1V9+Pcuk9BMR/vrXvPfc6p33veU7eqLu2wQQACEIBA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Q/ABYNIUABCBQMwEEv2bvYTsEIACBAAIIfgAsmkIAAhComQCCX7P3sB0CEIBAAAEEPwAWTSEAAQjUTADBr9l72A4BCEAggACCHwCLphCAAARqJoDg1+w9bIcABCAQQADBD4BFUwhAAAI1E0Dwa/YetkMAAhAIIIDgB8CiKQQgAIGaCSD4NXsP2yEAAQgEEEDwA2DRFAIQgEDNBBD8mr2H7RCAAAQCCCD4AbBoCgEIQKBmAgh+zd7DdghAAAIBBBD8AFg0hQAEIFAzAQS/Zu9hOwQgAIEAAgh+ACyaQgACEKiZAIJfs/ewHQIQgEAAAQQ/ABZNIQABCNRMAMGv2XvYDgEIQCCAAIIfAIumEIAABGomgODX7D1shwAEIBBAAMEPgEVTCEAAAjUTQPBr9h62QwACEAgggOAHwKIpBCAAgZoJIPg1ew/bIQABCAQQQPADYNEUAhCAQM0EEPyavYftEIAABAIIIPgBsGgKAQhAoGYCCH7N3sN2CEAAAgEEEPwAWDSFAAQgUDMBBL9m72E7BCAAgQACCH4ALJpCAAIQqJkAgl+z97AdAhCAQAABBD8AFk0hAAEI1Ezg/wFm7lJkZahzkgAAAABJRU5ErkJggg==";
list($ignore, $imgData) = explode(',', $input);
$image = imagecreatefromstring(base64_decode($imgData));
imagealphablending($image, true); // setting alpha blending on
imagesavealpha($image, true); // save alphablending setting
//my code works up until this point (I can output a transparent PNG successfully)
//this is where I would make a new image with-
//the transparent background and put my transparent PNG on it-
//to prep it for imagegif();
//i kinda had some success with:
//$fill = imagecolorallocate($image, 255, 250, 214);
//imagefill($image, 0, 0, $fill);
//just to test if I could actually change the background..
//but anything like a circle with a transparent center would not--
//get filled with transparency and would remain black.
//so this obviously isn't the way to do it.
imagegif($img, 'test.gif');
The end result has to be a GIF preserving the PNG's transparent background.
I'm really stuck ¬____¬ please help me.
Thank you in advance for any advice you can provide.
Edit:
To show you an example of why chrislondon's second example does not work, I have drawn a half circle and a full circle in this image and then spun it through chrislondon's code (resulting in a .GIF image which is what I want):
The (lumpy)black circle is not filled by me, it is just the transparency in the center not showing through. The (lumpy)circle to the right is not completed all the way leaving a gap and so the transparency is filled.
I hope this will clear up any remaining misunderstandings to what I'm trying to achieve.
imagecolortransparent($image, 127<<24); // 0x7f000000
The GD library stores the alpha in a weird way.
0x7f000000 = 100% transparent black
0x00000000 = 100% opaque black
So choosing the transparent black, over the opaque black color, will make it transparent.
This appears to work:
$input = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAXwAAAEYCAYAAABfgk2GAAAemklEQVR4Xu2dzYsm13WHe7rHxGATtw1Zu8UMY0wIkv6AoF44ZOEspFWyUytkkRASJG0sgS2NPkCKF5qxMSSboNbOu4xJcAxZaJRNlhqRVYaZpPUPSC2wiYmm38k5rS75delW1b1V9+Pcuk9BMR/vrXvPfc6p33veU7eqLu2wQQACEIBAEwQuNTFLJgkBCEAAAjsIPkEAAQhAoBECCH4jjmaaEIAABBB8YgACEIBAIwQQ/EYczTQhAAEIIPjEAAQgAIFGCCD4jTiaaUIAAhBA8IkBCEAAAo0QQPAbcTTThAAEIIDgEwMQgAAEGiGA4DfiaKYJAQhAAMGvJwYeE1OfkP3JC5P3L/48vfjzlvz5nux36pkSlkIAAjkJIPg5ac8b60gOe1n2A8/DT6Tdddnf8WxPMwhAoBECCL5dRx+KaW8HCH1/Jir8T5Hx23UwlkEgNwEEPzdxv/E0q1exj7E9I50cx+iIPiAAgboJIPj2/Kfi/HRks7RPFX62dRLg+s46/Rp9Vgh+dKSLOoyZ2fcNIdNf5BqTB2u8cH3HpGtsGoXg2/HLoZjybmJzHpf+WcWTGHKG7jVWuL6TAfTahkDw7Xj0REz5ZmJzdIxHEo9B92kJxPwVyK++tL4y1zuCb8MlMU/iqRn9nTR4YaoRn5skcCxWcX3HpGvqMArBt+GnHNl9N9ON/GXPxrSxIoBAyqSATD/AETU3RfDLe09XWLyf2Qxq+ZmBLxzuUI7n+s5CiBy+w0vMDQTBs2LDjcx2PCfj3cw8JsPNJ5DjF6COwfWd+T6q4kgy/PJuui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$input);
$image = imagecreatefromstring(base64_decode($imgData));
$width = imagesx($image);
$height = imagesy($image);
$imageOut = imagecreatetruecolor($width, $height);
//TODO - edges will be anti-aliased to this colour, pick one that will look
//'good' for you, e.g. mid-grey for general case, white for white pages,
$background = imagecolorallocatealpha($imageOut, 0x7f, 0x7f, 0x7f, 0);
imagefill($imageOut, 0, 0 , $background);
imagecopyresampled($imageOut, $image, 0, 0, 0, 0, $width, $height, $width, $height);
imagesavealpha($imageOut, true);
imagecolortransparent($imageOut, $background);
imagegif($imageOut, "../../var/tmp/test.gif");
The bit you missed was you have to explicitly say which colour should be set as transparent. It won't automatically convert the alpha channel to being transparent.
However this method is actually slightly dangerous, as whichever pixels are that colour will be transparent in the final image. You may be better choosing a colour unlikely to be present elsewhere e.g. rgb(0xff, 0xff, 0)
If you're fine with a PNG this works perfectly:
$input = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAXwAAAEYCAYAAABfgk2GAAAemklEQVR4Xu2dzYsm13WHe7rHxGATtw1Zu8UMY0wIkv6AoF44ZOEspFWyUytkkRASJG0sgS2NPkCKF5qxMSSboNbOu4xJcAxZaJRNlhqRVYaZpPUPSC2wiYmm38k5rS75delW1b1V9+Pcuk9BMR/vrXvPfc6p33veU7eqLu2wQQACEIBAEwQuNTFLJgkBCEAAAjsIPkEAAQhAoBECCH4jjmaaEIAABBB8YgACEIBAIwQQ/EYczTQhAAEIIPjEAAQgAIFGCCD4jTiaaUIAAhBA8IkBCEAAAo0QQPAbcTTThAAEIIDgEwMQgAAEGiGA4DfiaKYJAQhAAMGvJwYeE1OfkP3JC5P3L/48vfjzlvz5nux36pkSlkIAAjkJIPg5ac8b60gOe1n2A8/DT6Tdddnf8WxPMwhAoBECCL5dRx+KaW8HCH1/Jir8T5Hx23UwlkEgNwEEPzdxv/E0q1exj7E9I50cx+iIPiAAgboJIPj2/Kfi/HRks7RPFX62dRLg+s46/Rp9Vgh+dKSLOoyZ2fcNIdNf5BqTB2u8cH3HpGtsGoX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gEVTCEAAAjUTQPBr9h62QwACEAgggOAHwKIpBCAAgZoJIPg1ew/bIQABCAQQQPADYNEUAhCAQM0EEPyavYftEIAABAIIIPgBsGgKAQhAoGYCCH7N3sN2CEAAAgEEEPwAWDSFAAQgUDMBBL9m72E7BCAAgQACCH4ALJpCAAIQqJkAgl+z97AdAhCAQAABBD8AFk0hAAEI1Ezg/wFm7lJkZahzkgAAAABJRU5ErkJggg==";
$image = imagecreatefrompng($input);
imagesavealpha($image, true);
imagepng($image, 'test.png');
If you want to convert it to a GIF you have to fill in the transparent color like this:
$input = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAXwAAAEYCAYAAABfgk2GAAAemklEQVR4Xu2dzYsm13WHe7rHxGATtw1Zu8UMY0wIkv6AoF44ZOEspFWyUytkkRASJG0sgS2NPkCKF5qxMSSboNbOu4xJcAxZaJRNlhqRVYaZpPUPSC2wiYmm38k5rS75delW1b1V9+Pcuk9BMR/vrXvPfc6p33veU7eqLu2wQQACEIBAEwQuNTFLJgkBCEAAAjsIPkEAAQhAoBECCH4jjmaaEIAABBB8YgACEIBAIwQQ/EYczTQhAAEIIPjEAAQgAIFGCCD4jTiaaUIAAhBA8IkBCEAAAo0QQPAbcTTThAAEIIDgEwMQgAAEGiGA4DfiaKYJAQhAAMGvJwYeE1OfkP3JC5P3L/48vfjzlvz5nux36pkSlkIAAjkJIPg5ac8b60gOe1n2A8/DT6Tdddnf8WxPMwhAoBECCL5dRx+KaW8HCH1/Jir8T5Hx23UwlkEgNwEEPzdxv/E0q1exj7E9I50cx+iIPiAAgboJIPj2/Kfi/HRks7RPFX62dRLg+s46/Rp9Vgh+dKSLOoyZ2fcNIdNf5BqTB2u8cH3HpGtsGoXg2/HLoZjybmJzHpf+WcWTGHKG7jVWuL6TAfTahkDw7Xj0REz5ZmJzdIxHEo9B92kJxPwVyK++tL4y1zuCb8MlMU/iqRn9nTR4YaoRn5skcCxWcX3HpGvqMArBt+GnHNl9N9ON/GXPxrSxIoBAy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AAgQACCH4ALJpCAAIQqJkAgl+z97AdAhCAQAABBD8AFk0hAAEI1Ezg/wFm7lJkZahzkgAAAABJRU5ErkJggg==";
$image = imagecreatefrompng($input);
$transparent = imagecolorallocatealpha($image, 255, 255, 255, 127);
imagefill($image, 0, 0, $transparent);
imagegif($image, 'test.gif');
Note that because your string is an image/png you can use imagecreatefrompng and not have to do any comma exploding :)
Try this:
list($ignore, $imgData) = explode(',', $input);
$image = imagecreatefromstring(base64_decode($imgData));
$fill = imagecolorallocate($image, 255, 250, 214);
imagecolortransparent($image, $fill);
imagefill($image, 0, 0, $fill);
imagegif($image);
I would like to change the color of an image with php.
if I wanted to make it appear redder applicherei an image on a higher level across an image with a transparent red and more or less high can indicate how the original photo should be red.
I can say gd php functions to create an image of a color (RGBA) and apply it to another image?
thanks :)
You can try using GD's imagecopymerge function, which copies one image to another and supports alpha transparency. Something like this should work:
<?php
$redimg = imagecreatetruecolor(100, 100);
$image = imagecreatefrompng('image.png');
// sets background to red
$red = imagecolorallocate($redimg, 255, 0, 0);
imagefill($redimg, 0, 0, $red);
// Merge the red image onto the PNG image
imagecopymerge($image, $redimg, 0, 0, 0, 0, 100, 100, 75);
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
imagedestroy($redimg);
?>
There's more information here.
i'm working on creating one PNG image from two others.
Image A and B have the same dimensions, they are both 200x400px. The final image the same.
I'm using the GD library with PHP.
So my idea was to create a PNG-24 from my original PNG-8, then use color transparency and finally copy the second image into
this new PNG-24. The problem appears in the first step anyway, when going from PNG-24 to PNG-8 with color transparency:
This is to get the original PNG-8 and it's dimensions:
$png8 = imagecreatefrompng($imageUrl);
$size = getimagesize($imageUrl);
Now i create a new PNG and fill it's background with a green color (not present in the images):
$png24 = imagecreatetruecolor($size[0], $size[1]);
$transparentIndex = imagecolorallocate($png24, 0x66, 0xff, 0x66);
imagefill($png24, 0, 0, $transparentIndex);
This is for making the green color transparent:
imagecolortransparent($png24, $transparentIndex);
Then i copy the png8 into the PNG-24:
imagecopy($png24, $png8, 0, 0, 0, 0, $size[0], $size[1]);
So here's the problem: the original PNG-8 looks good, but it has a green border surrounding the shape within the original image. It's difficult to explain really. Seems like some part of the green background is left in the remaining PNG.
What can i do?
thanks in advance
best regards,
Fernando
I had some problems with png transparency before and was able to solve them with this pattern:
// allocate original image to copy stuff to
$img = imagecreatetruecolor(200, 100);
// create second image
$bg = imagecreatefrompng('bg.png');
// copy image onto it using imagecopyresampled
imagecopyresampled($img, $bg, 0, 0, 0, 0, 200, 100, 200, 100);
imagedestroy($bg);
// create third image
// do same routine
$fg = imagecreatefrompng('fg.png');
imagecopyresampled($img, $fg, 50, 50, 0, 0, 50, 50, 50, 50);
imagedestroy($fg);
// output image
imagepng($img);
imagedestroy($img);
I think the only difference between mine and yours is imagecopy() vs. imagecopyresampled(). I seem to remember having problems with that though it was quite a while ago. You can see an example of an image I use this pattern on here: http://www.ipnow.org/images/1/bggrad/bg4/yes/TRANSIST.TTF/8B0000/custombrowserimage.jpg (I allocate a blank image, copy the background image in, copy the overlay with transparency in)
This one is empty image before writing
Here is my code
<?php
function LoadJpeg($imgname)
{
$im = #imagecreatefromjpeg($imgname);
$grey = imagecolorallocate($im, 255, 255, 0);
// The text to draw
$text = 'http://www.stackoverflow.com';
// Replace path by your own font path
$font = 'CONSOLA.TTF';
list($width, $height) = getimagesize($imgname);
// wants to know how to use this width/height dynamically //
imagettftext($im, 20, 45, 200, 450, $grey, $font, $text);
return $im;
}
header('Content-Type: image/jpeg');
$img = LoadJpeg('Blue_hills.jpg');
imagejpeg($img);
imagedestroy($img);
?>
Image after writing text on it
What I want is vertically and horizontally center the text on 45 degree. Please help me on this. Thanks for you all.
Use the imagettfbbox function to retrieve the dimensions the text rendering would require. Then use that information to calculate the x,y coordinate you should target within the destination image for the text to be centered respective to the width/height.
I know very little about PHP (I'm making this up as I go along).
I'd recommend making a new square image, setting it to have a transparent background with imagecolortransparent(). Then write the text to the transparent image.
Next I'd try using imagecopyresized() to copy and scale the text to the new window. Use the minimum of the original's height and width for the destination size. The offset would be something like (max($width, $height)-min($width, $height))/2. Apply the offset to whichever dimension is greater.