mrkeck Sharing the Love


PHP GD jpg too large

This one had me stumped for a while. I am using WAMP, but has nothing to do with the issue.

I was trying to manipulate a jpg that was 1.3MB, which I was sure was not too large. However, that is the compressed size. Once it is loaded into GD it is no longer compressed. In order to calculate the uncompressed size, multiply the pixel width times pixel height times 4 (conversion rate from pixels to bytes)

(w x h x 4)

Make sure the memory_limit in php.ini is large enough to handle the load


Assume sample jpg is 1.3MB and has width of 2,500 pixels and height of 5,000 pixels
(2500 x 5000 x 4)=50,000,000 (50MB)

Filed under: GD, PHP No Comments

PHP GD Add TImestamp to Image

function addTimestamp($imgName){
	//Get image
	$img = ImageCreateFromJPEG($imgName);
	//Make timestamp image
	$im = imagecreatetruecolor(240, 200);
	$color_black = ImageColorAllocate($img, 255, 255, 255); 
	//Put timestamp image on top of main image
	imagecopymerge($img, $im, 0, 0, 0, 0, 240, 20, 60);
	//Overwrite original with one with timestamp
Filed under: GD, PHP No Comments