mk.
mk.

Reputation: 26216

Generated image using PHP and GD is being cut off

This is only happening on the live server. On multiply development servers the image is being created as expected.

LIVE: Red Hat

$ php --version
PHP 5.2.6 (cli) (built: May 16 2008 21:56:34) 
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies

GD Support => enabled GD Version => bundled (2.0.34 compatible)

DEV: Ubuntu 8

$ php --version
PHP 5.2.4-2ubuntu5.3 with Suhosin-Patch 0.9.6.2 (cli) (built: Jul 23 2008 06:44:49) 
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies

GD Support => enabled GD Version => 2.0 or higher

<?php
$image = imagecreatetruecolor($width, $height);

// Colors in RGB
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0); 

imagefilledrectangle($image, 0, 0, $width, $height, $white);

imagettftext($image, $fontSize, 0, 0, 50, $black, $font, $text);
imagegif($image, $file_path);
?>

In a perfect world I would like the live server and the dev server to be running the same distro, but the live server must be Red Hat.

My question is does anyone know the specific differences that would cause the right most part of an image to be cut off using the bundled version of GD?

EDIT: I am not running out of memory. There are no errors being generated in the logs files. As far as php is concerned the image is being generated correctly. That is why I believe it to be a GD specific problem with the bundled version.

Upvotes: 2

Views: 2406

Answers (5)

Darkerstar
Darkerstar

Reputation: 932

It might not be the image is being cut off. It might be the text being cut off.

imagettftext($image, $fontSize, 0, 0, 50, $black, $font, $text);

TTF font has overhead and paddings. Try a larger canvas see if the you get the same result.

Upvotes: 0

NineBerry
NineBerry

Reputation: 28559

Have you had the value of $width output to see whether it is correct?

Upvotes: 0

William Macdonald
William Macdonald

Reputation: 2167

Does it depend on the image ?

Recently I discovered a strange bug/feature in PHP & GD.

When trying to resize and edit JPEGs that had an all white background (c. 3MB), it would fail. It DID work with other images that were larger (c. 4MB), and more complicated backgrounds.

I worked out that when GD opened the images to edit, the white back ground images grew by a greater ratio than the more complex images. This ratio for some images caused PHP/GD to fail and cut of images halfway.

William

Upvotes: 0

Devin Ceartas
Devin Ceartas

Reputation: 4829

Is it 100% consistent and always at the same place? If not, it might be a resource issue -- time to execute the script or memory limitation. Try tweaking the php.ini settings, rebooting web server, testing.

Upvotes: 0

Till
Till

Reputation: 22436

Maybe you are running out of memory or something similar? Did you double check all logfiles, etc.?

Upvotes: 2

Related Questions