imagettfbbox & imagettftext - resize,position,rotate - php

Ok, now it's officialy 10 hours that I'm trying to make this work, but by every minute I'm farther and farther from the final goal...
The thing is, I need to create a function, class or whatever that by the selected TTF or truetype font create, properly resize, and fill the image with a text given by the url. The image shouldn't be longer than that text.
I've given up on all my codes, and the best thing I've got so far is taken from the net ...
<?php
if(!isset($_GET['size'])) $_GET['size'] = 20;
if(!isset($_GET['text'])) $_GET['text'] = "Moj tekst";
$get_font = ( isset( $_GET['font'] ) ) ? $_GET['font'] : 'arial';
$size = imagettfbbox($_GET['size'], 0, "font/".$get_font.".ttf", $_GET['text']);
$xsize = abs($size[0]) + abs($size[2]);
$ysize = abs($size[5]) + abs($size[1]);
$image = imagecreate($xsize, $ysize);
imageSaveAlpha($image, true);
ImageAlphaBlending($image, false);
$transparentColor = imagecolorallocatealpha($image, 200, 200, 200, 127);
Imagefill($image, 0, 0, $transparentColor);
$blue = imagecolorallocate($image, 0, 0, 255);
$white = ImageColorAllocate($image, 255,255,255);
$black = ImageColorAllocate($image, 0,0,0); //-($_GET['size']/20)
imagettftext($image, $_GET['size'], 0, abs($size[0]), abs($size[5]), $black, "font/".$get_font.".ttf", $_GET['text']);
header("content-type: image/png");
imagepng($image);
imagedestroy($image);
?>
This code is ok, although the edge of the last or first latter is sometimes partly hidden or just it doesn't fit into the created image (depending on font size), which isn't the problem with smaller font size. And the function i really need is by changing image's rotation to change the entire images proportions so the text fits in.
Example : http://img199.imageshack.us/img199/9368/32739521.jpg
Also, if there is finished function or class that does this, it would be great.. :'( :)

If you are always missing one letter of the end of the beginning, why not just add the width of a single letter to your final size?
In my experience, imagettfbbox doesn't do a very good job of deciding what does and doesn't fit within a bounding box - you need to fudge it a little yourself :)
Hope this helps.
Luke Peterson

Related

Creating image with fix background and randomly displayed text from a pre-defined list

I would like to create a script which is generating an image with one fix background image but display a randomly selected sentence on the image from a list which is previously given in the script.
So far I have a base and I've tried many variations for the random text, but none of them worked until this time.
Here is the script itself:
<?php
header('Content-type: image/png');
$text = 'The text which will be displayed';
$background_path = 'assets/bg_image.jpg';
$image = imagecreatetruecolor(1280, 720);
$background = imagecreatefromjpeg($background_path);
$color = imagecolorallocate($image, 255, 255, 255);
$title_sizes = imagettfbbox(24, 0, 'assets/roboto-medium.ttf', $text);
$title_height = $title_sizes[3];
$title_width = $title_sizes[4];
imagecopy($image, $background, 0, 0, 0, 0, 1280, 720);
imagettftext($image, 24, 0, (640 - $title_width / 2), (360 - $title_height / 2), $color, 'assets/roboto-medium.ttf', $text);
imagepng($image);
imagedestroy($image);
imagedestroy($background);
?>
So the thing is that the line "$text" allows only one sentence to be displayed. I would like to have multiple lines (various sentences) instead which will be displayed on the given background image randomly upon refresh.
Can you please help me to solve this problem?
Thank you very much in advance!
Regards,
Adam

Black background on GIF instead of transparency in PHP using imagegif()

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/EYczTQhAAEIIPjEAAQgAIFGCCD4jTiaaUIAAhBA8IkBCEAAAo0QQPAbcTTThAAEIIDgEwMQgAAEGiGA4DfiaKYJAQhAAMGvJwYeE1OfkP3JC5P3L/48vfjzlvz5nux36pkSlkIAAjkJIPg5ac8b60gOe1n2A8/DT6Tdddnf8WxPMwhAoBECCL5dRx+KaW8HCH1/Jir8T5Hx23UwlkEgNwEEPzdxv/E0q1exj7E9I50cx+iIPiAAgboJIPj2/Kfi/HRks7RPFX62dRLg+s46/Rp9Vgh+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IQCCAAIIfAIumEIAABGomgODX7D1shwAEIBBAAMEPgEVTCEAAAjUTQPBr9h62QwACEAgggOAHwKIpBCAAgZoJIPg1ew/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/vrXvPfc6p33veU7eqLu2wQQACEIBAEwQuNTFLJgkBCEAAAjsIPkEAAQhAoBECCH4jjmaaEIAABBB8YgACEIBAIwQQ/EYczTQhAAEIIPjEAAQgAIFGCCD4jTiaaUIAAhBA8IkBCEAAAo0QQPAbcTTThAAEIIDgEwMQgAAEGiGA4DfiaKYJAQhAAMGvJwYeE1OfkP3JC5P3L/48vfjzlvz5nux36pkSlkIAAjkJIPg5ac8b60gOe1n2A8/DT6Tdddnf8WxPMwhAoBECCL5dRx+KaW8H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D8AFg0hQAEIFAzAQS/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,iVBORw0KGgoAAAANSUhEUgAAAXwAAAEYCAYAAAB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khnu1cPhdUiYRzQRXjzwV1b+fBrTPJUNNn9Ak8QJc1EdgWfrV7e2VJTfOowdaQsk4VOmYBOqAseAEbIACBIQI+mT465hk/gPIERTMIQKAIgalMn1U6AW5B8ANg0RQCEIBAzQQQ/Jq9h+0QgAAEAggg+AGwaAoBCECgZgIIfs3ew3YIQAACAQQQ/ABYNIUABCBQMwEEv2bvYTsEIACBAAIIfgAsmkIAAhComQCCX7P3sB0CEIBAAAEEPwAWTSEAAQjUTADBr9l72A4BCEAggACCHwCLphCAAARqJoDg1+w9bIcABCAQQADBD4BFUwhAAAI1E0Dwa/YetkMAAhAIIIDgB8CiKQQgAIGaCSD4NXsP2yEAAQgEEEDwA2DRFAIQgEDNBBD8mr2H7RCAAAQCCCD4AbBoCgEIQKBmAgh+zd7DdghAAAIBBBD8AFg0hQAEIFAzAQS/Zu9hOwQgAIEAAgh+ACyaQgACEKiZAIJfs/ewHQIQgEAAAQQ/ABZNIQABCNRMAMGv2XvYDgEIQCCAAIIfAIumEIAABGomgODX7D1shwAEIBBAAMEPgEVTCEAAAjUTQPBr9h62QwACEAgggOAHwKIpBCAAgZoJIPg1ew/bIQABCAQQQPADYNEUAhCAQM0EEPyavYftEIAABAIIIPgBsGgKAQhAoGYCCH7N3sN2CEAAAgEEEPwAWDSFAAQgUDMBBL9m72E7BCAAgQACCH4ALJpCAAIQqJkAgl+z97AdAhCAQAABBD8AFk0hAAEI1Ezg/wFm7lJkZahzkgAAAABJRU5ErkJggg==";
list($ignore, $imgData) = explode(',', $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+dKSLOoyZ2fcNIdNf5BqTB2u8cH3HpGtsGoXg2/HLoZjybmJzHpf+WcWTGHKG7jVWuL6TAfTahkDw7Xj0REz5ZmJzdIxHEo9B92kJxPwVyK++tL4y1zuCb8MlMU/iqRn9nTR4YaoRn5skcCxWcX3HpGvqMArBt+GnHNl9N9ON/GXPxrSxIoBAyqSATD/AETU3RfDLe09XWLyf2Qxq+ZmBLxzuUI7n+s5CiBy+w0vMDQTBs2LDjcx2PCfj3cw8JsPNJ5DjF6COwfWd+T6q4kgy/PJuui0m6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ealpha($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/GXPxrSxIoBAyqSATD/AETU3RfDLe09XWLyf2Qxq+ZmBLxzuUI7n+s5CiBy+w0vMDQTBs2LDjcx2PCfj3cw8JsPNJ5DjF6COwfWd+T6q4kgy/PJuui0m6DNycm76zB3NGtnsEzgSE2PdhDc1W0o7U4Qq/xzBL+9ABL+8DyxbkCO77+ZPlm85EiLYhuBHgLiwC10X/+jCPkIP1zG1js9mmwDXd2z7pzrrEPzyLish+B/ItFVM2GwT4PqObf9UZx2CX95llHTK+8C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ToM6z/R0RSN8XnJ8L/d71a6f3Mwvq+asQRVA1a9dt70JQzy4EdU8E9UwENXlGvzwi6MFFQP2pWafu28+nafXehBxRguAnoGxa8Lv56h25e5Khnu1cPhdUiYRzQRXjzwV1b+fBrTPJUNNn9Ak8QJc1EdgWfrV7e2VJTfOowdaQsk4VOmYBOqAseAEbIACBIQI+mT465hk/gPIERTMIQKAIgalMn1U6AW5B8ANg0RQCEIBAzQQQ/Jq9h+0QgAAEAggg+AGwaAoBCECgZgIIfs3ew3YIQAACAQQQ/ABYNIUABCBQMwEEv2bvYTsEIACBAAIIfgAsmkIAAhComQCCX7P3sB0CEIBAAAEEPwAWTSEAAQjUTADBr9l72A4BCEAggACCHwCLphCAAARqJoDg1+w9bIcABCAQQADBD4BFUwhAAAI1E0Dwa/YetkMAAhAIIIDgB8CiKQQgAIGaCSD4NXsP2yEAAQgEEEDwA2DRFAIQgEDNBBD8mr2H7RCAAAQCCCD4AbBoCgEIQKBmAgh+zd7DdghAAAIBBBD8AFg0hQAEIFAzAQS/Zu9hOwQgAIEAAgh+ACyaQgACEKiZAIJfs/ewHQIQgEAAAQQ/ABZNIQABCNRMAMGv2XvYDgEIQCCAAIIfAIumEIAABGomgODX7D1shwAEIBBAAMEPgEVTCEAAAjUTQPBr9h62QwACEAgggOAHwKIpBCAAgZoJIPg1ew/bIQABCAQQQPADYNEUAhCAQM0EEPyavYftEIAABAIIIPgBsGgKAQhAoGYCCH7N3sN2CEAAAgEEEPwAWDSFAAQgUDMBBL9m72E7BCAAgQACCH4ALJpCAAIQqJkAgl+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);

PHP/GD - transparent background

I want to do the following in PHP in combination with GD. ImageMagick is not an option, unfortunately, but this seems like such a common problem that there has to be a solution, I just can't seem to find it.
I want to create a PNG with a transparent background. Then I want to draw a rectangle on it, copy an image on it, and add some text. One way of doing this is as follows:
$image = ImageCreateTrueColor (800, 600);
imagecolortransparent ($image, 0); //0 is pure black, the default fill color
imagerectangle (...);
//code to copy an image
imagettftext ($image, ...);
imagepng ($image);
This works fine, except that part of the copied image might be black, and/or the text might be black. This then also becomes transparent, which is something I don't want.
imagefill ($image, 0,0, 0x7FFF0000);
imagetransparent ($image, 0x7FFF0000);
The above code is something I found online, which fills it with red, then makes red transparent. Again, this causes all red in the image to become transparent. I could choose a color that is unlikely to occur, but I can't guarantee this.
Is there something I'm missing? Can this be fixed?
Thanks for your replies!
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 = imagecolorallocate($image, 0, 0, 0);
imagefilledrectangle($image, 25, 25, 75, 75, $black);
header('Content-Type: image/png');
imagepng($image);

ImageGD not filling correctly

Hay, I'm using this code to generate an image and fill it with a gray colour.
$canvas = imagecreatetruecolor(100, 100);
$gray = imagecolorallocate($canvas, 0xEE, 0xEE, 0xEE);
imagefill($canvas, 0, 0, $gray);
imagegif($canvas);
This works fine, but if i change the canvas size to a 'long' image, it fails to fill.
$canvas = imagecreatetruecolor(1, 100);
Is this a common bug? Or do i need some other option? How do i fill the whole canvas?
Looks like a bug. I confirm the same behavior. It fills only top 2 pixels, if you specify the width to be 1. The similar for 2 or 3. 4 seems like a magic value - it begins to work there.
On the other hand this bug doesn't seem to appear if you use a 1px-high image, i.e. I tried this and it worked as expected:
$canvas = imagecreatetruecolor(100, 1);
$red = imagecolorallocate($canvas, 0xEE, 0, 0);
imagefill($canvas, 0, 0, $red);
imagegif($canvas, "output.png");
So this might be a kind of a workaround.

Improving Performance on this Image Creation function

I am making use of GD2 and the image functions to take in a string and then convert that into an image using different fonts at different sizes. The function I use is below.
Currently, its pretty quick but not quick enough. The function gets called about 20 times per user and the images generated are always new ones (different) so caching isn't going to help!
I was hoping to get some ideas on how to make this function faster. Maybe supply more RAM to the script running? Anything else that is specific to this PHP function?
Anything else that I can do to tweak performance of this function?
function generate_image($save_path, $text, $font_path, $font_size){
$font = $font_path;
/*
* I have simplifed the line below, its actually a function that works out the size of the box
* that is need for each image as the image size is different based on font type, font size etc
*/
$measure = array('width' => 300, 'height'=> 120);
if($measure['width'] > 900){ $measure['width'] = 900; }
$im = imagecreatetruecolor($measure['width'], $measure['height']);
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, $measure['width'], $measure['height'], $white);
imagettftext($im, $font_size, 0, $measure['left'], $measure['top'], $black, $font, ' '.$text);
if(imagepng($im, $save_path)){
$status = true;
}else{
$status = false;
}
imagedestroy($im);
return $status;
}
Thanks all for any help
I think its good
Instead of creating a new image each time, you could have a blank PNG file (we already know that the maximum width is 900px, do you have a fixed maximum height you can use?), open it, add your text, and then crop it (see imagecopy()).
I'm not sure, but it might be faster than what you are currently doing.

Categories