View Full Version : No generated image nomore
bojangles
01-29-2016, 06:43 AM
Im still working at fixing a website code after the server was upgraded. This no longer works. Any help from anyone?
$width = 250; // width of bar
$height = 25; // height of bar
$per = imagecreate($width, $height);
$background = imagecolorallocate($per, 0xFF, 0xFF, 0xFF);
$foreground = imagecolorallocate($per, 0x00, 0x8A, 0x01);
$border = imagecolorallocate($per, 0x99, 0x99, 0x99);
if ($_GET['per'] > 0){
$grad = imagecreatefrompng("bar.png");
$per2 = imagecopy($per, $grad, 1, 1, 0, 0, ($_GET['per']*$width/100), ($height-2));
imagerectangle($per, 0, 0, ($width-1), ($height-1), $border);
}
header("Content-type: image/png");
imagepng($per, NULL, ($height-2));
Beverleyh
01-29-2016, 08:07 AM
Hmmm, the code looks incomplete. For example, the $background and $foreground variables don't look like they're ever used (in this snippet).
Is this *all* the script? And are you able to elaborate on "This no longer works" - are you getting errors on screen to say what isn't working?
bojangles
01-29-2016, 09:52 AM
Thanks for replying Bev. I couldn't tell you what the variables are. Having looked through the script (and this is very almost everything except for the img below) I can't tell where they are used. All I know is that the image used to be generated but after the server upgrade it no longer is.
It is visible in an img <img src="image.php?per=77">
The "per" part of the src makes the bar image longer but now all it does is show as broken. No image generated nomore.
styxlawyer
01-29-2016, 10:26 AM
Try adding a few debugging statements to find out where it's going wrong:
$width = 250; // width of bar
$height = 25; // height of bar
$per = imagecreate($width, $height) or die("Cannot initialise image stream.");
$background = imagecolorallocate($per, 0xFF, 0xFF, 0xFF) or die("Cannot add background colour.");
$foreground = imagecolorallocate($per, 0x00, 0x8A, 0x01) or die("Cannot add foreground colour.");
$border = imagecolorallocate($per, 0x99, 0x99, 0x99) or die("Cannot add border colour.");
if ($_GET['per'] > 0){
$grad = imagecreatefrompng("bar.png");
$per2 = imagecopy($per, $grad, 1, 1, 0, 0, ($_GET['per']*$width/100), ($height-2));
imagerectangle($per, 0, 0, ($width-1), ($height-1), $border);
}
header("Content-type: image/png");
imagepng($per, NULL, ($height-2));
styxlawyer
01-29-2016, 12:29 PM
... an afterthought. You said it's happened as a result of a server upgrade. Have you ensured that the GD library is enabled in your php.ini file?
Beverleyh
01-29-2016, 01:23 PM
I'm tempted to say that this line is the problem;
imagepng($per, NULL, ($height-2)); The last parameter - where you have ($height-2) - was introduced in PHP 5.1.2. It is a quality setting from 0-9 or -1, so your ($height-2) is likely causing it to fail because the result falls outside the allowed values. I'm not sure why that's in there but I'm guessing that your server has upgraded from PHP4 where the quality parameter was just being ignored, regardless of whatever value was being calculated.
Try changing it to this (6 is default quality) to see if it helps
imagepng($per, NULL, 6); OR try omitting the quality parameter setting altogether;
imagepng($per, NULL);
Let me know how it goes.
bojangles
01-29-2016, 02:29 PM
Bev has got me covered yet again! You got it in one and your suggestion has completely solved the issue. My image is back where it was :)
Amazingly helpful as always! Thank you.
Beverleyh
01-29-2016, 03:25 PM
Brilliant. Happy to help :)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.