gd

Calculating Text Width with PHP GD

邮差的信 提交于 2019-12-02 18:24:23
I'm simply trying to get the width of a dynamic line of text for addition to an image generated with GD PHP. I'm a little unsure how though. I know how to load a font using imageloadfont(), but can I use a .ttf file? I want to know the width of text using size 12 arial font. When I try to use my ttf file I get the error "Error reading font, invalid font header." If I need a .gdf file, where can I find a font size 12 gdf file? Here's my code: $newfont = imageloadfont("../fonts/arial.ttf"); $font_width = imagefontwidth($newfont); $font_height = imagefontheight($newfont); imageloadfont() is used

Make a (text to image) image a certain width but unlimited length?

让人想犯罪 __ 提交于 2019-12-02 17:07:48
问题 I have the code below that makes an image out of a large amount of text. I want that image to be 700px wide. I also want it to keep the paragraph structure that the string has. (the string is from a MySQL database.) How can i achieve that? $font = 2; $width = imagefontwidth($font) * strlen($string); $height = imagefontheight($font); $image = imagecreatetruecolor ($width,$height); $white = imagecolorallocate ($image,255,255,255); $black = imagecolorallocate ($image,0,0,0); imagefill($image,0,0

CentOS: Enabling GD Support in PHP Installation

此生再无相见时 提交于 2019-12-02 16:42:47
How do I go about enabling GD Support in a CentOS Installation? The thing that did the trick for me eventually was: yum install gd gd-devel php-gd and then restart apache: service httpd restart You need to find a repo that offers a GD lib matching your current php version. I've had great success using Remi Collet's repo for this purpose. In fact, I used it yesterday to update my php install to the latest 5.4.0RC6 version on my CentOS6 box. Once you've setup the repo it's a simple matter of running sudo yum install php-gd Of course, the usual things apply: make sure you restart apache after

What's the math behind CSS's background-size:cover

一曲冷凌霜 提交于 2019-12-02 15:54:31
I'm creating an "image generator" where users can upload an image and add text and/or draw on it. The outputted image is a fixed size (698x450). On the client side, when the user uploads their image it is set as the background of a div that's 698x450 with background-size:cover. This makes it fill the area nicely. The final combined image is generated by PHP using GD functions. My question is, how can I get the image to scale in PHP the same way it does in CSS. I want the result of the PHP script to look the same as if the image was set in CSS as it was above. Does anyone know how browsers

ImageMagick or GD Library for image resizing and thumbnail creation?

对着背影说爱祢 提交于 2019-12-02 13:09:53
I had been using the image resize class written by someone else to resize images or to create the thumbnails, here is the link to the class I had been using. http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php I guess image GD library has some limitations for the resolution or the file size of images, it works fine for low resolution picture resizing(below 1024px) but it does not resize if I try to upload the high resolution jpeg image (i.e 3400px X 2200px) roughly, The purpose for resizing the image is i am developing a picture gallery application. Is there any way I could

PHP convert 24-bit colors to 4-bit

帅比萌擦擦* 提交于 2019-12-02 12:27:50
Background, I am converting images to ascii art. This works perfectly and even works with 24-bit color, converting the colors to the right rgb values. However, I now want to render the ascii art in 4-bit color palette rather than 24-bit. How do I convert 24-bit colors to 4-bit with PHP? More specifically, I have the standard IRC color pallet which I need to convert any given Hexidecimal or RGB value to. It is preferred that the colors match as best as possible when converted to the 4-bit color. Other ideas I have had on this are to convert the image itself to a 4-bit palette (using GD, which

Colorize a PNG image using PHP GD

微笑、不失礼 提交于 2019-12-02 09:50:58
I've got a PNG image with a transparent background and a white circle. I'm trying to colorize the white circle into a specific color, but I'm having difficulty using this code: $src = imagecreatefrompng('circle.png'); $handle = imagecolorclosest($src, 255,255,255); imagecolorset($src,$handle,100,100,100); $new_image_name = "new_image.png"; imagepng($src,$new_image_name); imagedestroy($src) Any suggestions would be really helpful. Thank you in advance. Your PNG image I assume has alpha transparency, which makes imagecolorset() useless as you'll just remove the transparency (or end up with

imagecreatefrompng error

余生长醉 提交于 2019-12-02 08:39:53
<?php function LoadPNG($imgname) { /* Attempt to open */ $im = @imagecreatefrompng($imgname); /* See if it failed */ if(!$im) { /* Create a blank image */ $im = imagecreatetruecolor(150, 30); $bgc = imagecolorallocate($im, 255, 255, 255); $tc = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, 150, 30, $bgc); /* Output an error message */ imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc); } return $im; } header('Content-Type: image/png'); $img = LoadPNG('http://www.prideofhome.com/wp-content/uploads/328145505image_11.png'); imagepng($img); imagedestroy($img); ?> i am

Generate TTF via image(s) using PHP?

混江龙づ霸主 提交于 2019-12-02 07:49:13
问题 Are there existing libraries for generating .ttf via image(s) using PHP (say, a series of images)? There are several references about creating gdf from images, but I've not yet found examples of ttf-font creation via PHP. N.B. There are also several online resources that let you upload an image (write a letter in each box on an image template) to be instantly converted to a TTF. http://www.yourfonts.com is one of them 回答1: To my knowledge, there is no such tool. Creating a TrueType font is a

Make a (text to image) image a certain width but unlimited length?

自古美人都是妖i 提交于 2019-12-02 07:36:38
I have the code below that makes an image out of a large amount of text. I want that image to be 700px wide. I also want it to keep the paragraph structure that the string has. (the string is from a MySQL database.) How can i achieve that? $font = 2; $width = imagefontwidth($font) * strlen($string); $height = imagefontheight($font); $image = imagecreatetruecolor ($width,$height); $white = imagecolorallocate ($image,255,255,255); $black = imagecolorallocate ($image,0,0,0); imagefill($image,0,0,$white); imagestring ($image,$font,0,0,$string,$black); ob_start(); imagepng($image); printf('<img src