gd

reasonable PHP memory_limit for image resize

坚强是说给别人听的谎言 提交于 2019-11-30 16:21:45
问题 I want to enable users on my site to upload images to their accounts. The images get resized into 4 different sizes required across the site. I have been using Pear Image_Transform but I kept getting "bytes exhausted" fatal errors on certain types of jpgs (all files tried under 2mb). So I moved to a dedicated server with Pentium Dual-Core E5200 @ 2.50GHz and 2GB ram. Uploaded the same image resize code - same error. I upped the RAM in php.ini to 64M but site get the same problem on certain

Wrap lines of text within image boundaries using gd

江枫思渺然 提交于 2019-11-30 15:53:05
问题 I am trying to write text from a db to images. The text some times contains lengthy lines so that it does't fit in one line on image. As of now I am getting the output as: http://prntscr.com/29l582 This is the code for this: $imageCreator = imagecreatefrompng($i+1 . ".png"); $textColor = imagecolorallocate($imageCreator, 0, 0, 0); $textfromdb = $factformatted['fact']; $y = imagesy($imageCreator) - 228; $dimensions = imagettfbbox(20, 0, $fontname, $textfromdb); $x = ceil(($imageWidth -

Adding one image at the bottom of another in PHP

风流意气都作罢 提交于 2019-11-30 10:33:38
I'd like to add one image to the bottom of another in php I've this to load the images: //load top $top = @imagecreatefrompng($templateTop); //load bottom $bottom = @imagecreatefrompng($templateBottom); Now I'd like to add them to one picture and display top and bottom together. What way can I do this? Thanks! Use imagecopy : $top_file = 'image1.png'; $bottom_file = 'image2.png'; $top = imagecreatefrompng($top_file); $bottom = imagecreatefrompng($bottom_file); // get current width/height list($top_width, $top_height) = getimagesize($top_file); list($bottom_width, $bottom_height) = getimagesize

A fail-safe way to prevent GD image library from running out of memory? (PHP)

爷,独闯天下 提交于 2019-11-30 10:03:50
Is there a way to prevent the PHP GD image library from running out of memory? If too large an image is uploaded, GD tends to run out of memory, terminating the script. I'd like it to throw a catchable exception or something to that extend, but alas it doesn't. Right now I'm using a cobbled-together script that first issues an ini_set('memory_limit', '128M') , if that works I'm usually all set. Depending on the server configuration though that may not be possible, so I'm falling back on an algorithm that tries to estimate the amount of memory needed (taking resolution, color depth, channels

Create animated gif using the GD library

杀马特。学长 韩版系。学妹 提交于 2019-11-30 09:41:32
If I've got a bunch of image resources that I made using the GD library in php, or otherwise a bunch of frames, how can I combine these into an animated gif? I've got an array of images and a frames per second I'd like to add.. I can't use ImageMagick or FFMPEG, and I'd prefer to just use the GD library if possible. Apparently "Support for creating GIF animations is also available." , but I can't seem to find the documentation on how to access this from within PHP? Well searching on Google revealed GIFEncoder.class.php found at http://www.phpclasses.org/package/3163-PHP-Generate-GIF-animations

How to change the filename displayed in the “Save as…” dialog from .php to .png

被刻印的时光 ゝ 提交于 2019-11-30 09:28:39
问题 A simple PHP script that I picked up from stackoverflow generates a PNG with a transparent background, writes some text on it then directly outputs it to the client browser: $font = 25; $string = 'My Text'; $im = @imagecreatetruecolor(300, 300); imagesavealpha($im, true); imagealphablending($im, false); $white = imagecolorallocatealpha($im, 255, 255, 255, 127); $red = imagecolorallocate($im, 255, 0, 0); imagefill($im, 0, 0, $white); $lime = imagecolorallocate($im, 204, 255, 51); imagettftext(

image collage in PHP

做~自己de王妃 提交于 2019-11-30 09:04:58
I'm looking for a finshed solution or possibly some math/algorithms for creating a big image collage out of smaller product pictures? I know how to do it in a square fashion, from same sized pictures with gd/imagemagick but I'd like to have some variation built in. For example, some of the pictures might be slightly taller, and if all are the same size and square - i might want 1 of them take up more space, just to mix up the design. keeping it interesting. the more i think about this the harder it seems to do with a formula. having predefined "templates" for all the possible scenarios isn't

Enabling/installing GD extension? --without-gd

一世执手 提交于 2019-11-30 07:49:13
How does one enable (or perhaps I need to install) GD when my phpinfo() output in "Configure Command" says; --without-gd ? I also have nothing in my phpinfo() output "Core" that lists "gd" PHP Version 5.2.4 on AWS. if you are on a Debian based server (such as Ubuntu) you can run the following command: apt-get install php5-gd Then once it is complete run: /etc/init.d/apache2 restart This will restart your server and enable GD in PHP. If you are on another type of system you will need to use something else (like yum install) or compile directly into PHP. For PHP7.0 use ( php7.1-gd, php7.2-gd and

How do I fill white background while resize image

主宰稳场 提交于 2019-11-30 06:59:35
问题 Current background is black. How to change the color to be white? #assuming the mime type is correct switch ($imgtype) { case 'image/jpeg': $source = imagecreatefromjpeg($source_image); break; case 'image/gif': $source = imagecreatefromgif($source_image); break; case 'image/png': $source = imagecreatefrompng($source_image); break; default: die('Invalid image type.'); } #Figure out the dimensions of the image and the dimensions of the desired thumbnail $src_w = imagesx($source); $src_h =

PHP Detecting if source image url link leads to a “broken” image?

你离开我真会死。 提交于 2019-11-30 06:45:55
Suppose you have a thumbnail generator script that accepts source images in the form of a URL. Is there a way to detect if the source URL is "broken" - whether nonexistent or leads to an non-image file? Just brute force using getimagesize() or another PHP GD function is not a solution, since spoofed stray URL's that might not be images at all ( http://example.com/malicious.exe or the same file, but renamed as http://example.com/malicious.jpg ) could be input - such cases could easily be detected by PHP before having to invoke GD. I'm looking for GD pre-sanitizing before having GD try its