php-gd

How to account for font swash with PHP and GD

和自甴很熟 提交于 2019-12-10 13:07:30
问题 I have the following code to print text on an image. I am also adding a debug box around the text. However, I noticed the text on the left lies outside of the box that PHP gives me with imagettfbbox . This looks like an issue with the font swash. Is there anyway to account for this? Can I figure out the distance between the start of the swash and the actual position imagettfbbox gives to me? I don't think this is an issue with the font, as I tried it with a few script style fonts and the

PHP GD imagecreatefromstring discards transparency

别等时光非礼了梦想. 提交于 2019-12-10 03:26:17
问题 I've been trying to get transparency to work with my application (which dynamically resizes images before storing them) and I think I've finally narrowed down the problem after much misdirection about imagealphablending and imagesavealpha . The source image is never loaded with proper transparency! // With this line, the output image has no transparency (where it should be // transparent, colors bleed out randomly or it's completely black, depending // on the image) $img =

PHP wrong result for imagetruecolortopalette with PNG with transparency

痞子三分冷 提交于 2019-12-08 14:38:03
问题 I'm trying to write a PHP script that resizes a PNG image and then converts it to PNG-8 bit mode. So the size of the resulting file will be smaller but without too much quality loss. Edit: quote style for images to better show their transparency The resize works perfectly, preserving also image transparency: The problem is when I convert the image in 8 bit: imagetruecolortopalette($resizedImg, true, 255); imagealphablending($resizedImg, false); $transparent = imagecolorallocatealpha(

PHP - Add transparent PNG to GIF dynamically

好久不见. 提交于 2019-12-08 06:21:19
问题 I am trying to do a watermark mark with the php code, and everything seems to work fine, until I put a transparent PNG file to a GIF. This what happens: So instead of transparent black watermark, I get this semi solid green thing on the top. The watermark is I use the following php code: ... $image = imagecreatefromgif($filepath);; $watermark_image = imagecreatefrompng($wm_filepath); imagealphablending($watermark_image, false); imagesavealpha($watermark_image, true); imagegif($image,

PNG file is NOT keeping transparency?

a 夏天 提交于 2019-12-08 05:02:29
问题 I'll be using these variables throughout: $ROOTDIR = $_SERVER["DOCUMENT_ROOT"]; $ROOTFILE = "http://www.scottandjessiecooper.com/webtutorials/images/smiley.png"; $NEWFILE = "$ROOTDIR/images/tmp/new_smiley.png"; When I use this function, I have NO problems with transparency function save_image($root, $saveto){ copy($root, $saveto); } save_image( $ROOTFILE, $NEWFILE ); // root can be file or url However I NEED to use an IMAGE_RESOURCE so i cam manipulate the ROOTFILE if needed So i treid this:

imagecreatefrompng (and imagecreatefromstring) causes to unrecoverable fatal error

十年热恋 提交于 2019-12-07 05:00:27
问题 When I'm trying use php-gd functions on incorrect png images, I have Fatal PHP error. It seems to be some kind of bug, because accordingly to the functions documentation ( imagecreatefrompng , for example): * @return resource an image resource identifier on success, false on errors. But when I try to do it with my incorrect image, I have: Fatal error: imagecreatefrompng(): gd-png: fatal libpng error: Read Error: truncated data in /var/www/common/models/Utils.php on line 61 The code that leads

PHP - Add transparent PNG to GIF dynamically

可紊 提交于 2019-12-06 15:49:48
I am trying to do a watermark mark with the php code, and everything seems to work fine, until I put a transparent PNG file to a GIF. This what happens: So instead of transparent black watermark, I get this semi solid green thing on the top. The watermark is I use the following php code: ... $image = imagecreatefromgif($filepath);; $watermark_image = imagecreatefrompng($wm_filepath); imagealphablending($watermark_image, false); imagesavealpha($watermark_image, true); imagegif($image, $filepath); imagedestroy($image); imagecopy($image, $watermark_image, $offset['x'], $offset['y'], 0, 0, imagesx

Center text on image using PHP GD

流过昼夜 提交于 2019-12-06 15:09:51
So I am creating a banner generator. I will be adding text in the middle, but would like it to be exactly in the center. I know that imagettftext can be used to write onto the banner, but that won't center it. A likely solution could be to find the width of the text and then use half of it taken away from half of the banner width, but I've got no idea about how to do this. I am using PHP-GD and do not want to use anything else I will have to install. imagettftext($img, 14, 0, (468 - ((strlen($_GET['description']) * imagefontwidth(imageloadfont('minecraft.ttf'))) / 1)), 85, imagecolorallocate(

imagecreatefrompng (and imagecreatefromstring) causes to unrecoverable fatal error

南笙酒味 提交于 2019-12-05 10:35:20
When I'm trying use php-gd functions on incorrect png images, I have Fatal PHP error. It seems to be some kind of bug, because accordingly to the functions documentation ( imagecreatefrompng , for example): * @return resource an image resource identifier on success, false on errors. But when I try to do it with my incorrect image, I have: Fatal error: imagecreatefrompng(): gd-png: fatal libpng error: Read Error: truncated data in /var/www/common/models/Utils.php on line 61 The code that leads to this error is simple: $handle = imagecreatefrompng($fname); No code executes after this string. The

PHP GD imagecreatefromstring discards transparency

感情迁移 提交于 2019-12-05 03:41:35
I've been trying to get transparency to work with my application (which dynamically resizes images before storing them) and I think I've finally narrowed down the problem after much misdirection about imagealphablending and imagesavealpha . The source image is never loaded with proper transparency! // With this line, the output image has no transparency (where it should be // transparent, colors bleed out randomly or it's completely black, depending // on the image) $img = imagecreatefromstring($fileData); // With this line, it works as expected. $img = imagecreatefrompng($fileName); // Blah