Page 1 of 2
Help - IE7 doesn't print GD image - Solved thx
Posted: Sun Aug 05, 2007 9:39 pm
by robshanks
Hi
I am creating an image on the fly with PHP:
Code: Select all
<img src='scripts/sig.php?q=".$vehicleid."|".$vcdate."&sid=".rand()."' height='80px' width='240px' />
The website is https only and the created image displays perfectly in Firefox and MSIE 7. The image is also printed as expected by Firefox, however, MSIE will not print the image, just the red cross place holder.
Any ideas would be greatly appreciated.
Thanks in advance
Rob
Posted: Sun Aug 05, 2007 9:47 pm
by iknownothing
"|" is an illegal Windows filename character, which most likely is causing the issue with IE
No still no joy :(
Posted: Mon Aug 06, 2007 7:24 am
by robshanks
Hi iknownothing
Thanks for the input. I have changed the code to use an exclamation mark instead of the pipe character but the symptoms are exactly the same:
Code: Select all
<img src='scripts/sig.php?q=".$vehicleid."!".$vcdate."&sid=".rand()."' height='80px' width='240px' />
I am testing it on IE7 and it simply will not print the image which is displayed fine within the browser.
I am wondering it is a cahce vs https problem?
Any suggestions would be greatly appreciated.
Cheers
Rob
Posted: Mon Aug 06, 2007 9:06 am
by iknownothing
is this in PHP, or within HTML?
Code: Select all
<img src='scripts/sig.php?q=".$vehicleid."!".$vcdate."&sid=".rand()."' height='80px' width='240px' />
if PHP:
Code: Select all
echo "<img src='scripts/sig.php?q=" . $vehicleid . "!" . $vcdate. "&sid=" . rand() . "' height='80' width='240' />";
if HTML:
Code: Select all
<img src="scripts/sig.php?q=<?php echo $vehicleid; ?>!<?php echo $vcdate; ?>&sid=<?php echo rand() ?>" height="80" width="240" />
Also, I'm not sure if IE reads HTML (not CSS) coded sizes such as 240px, as 240px, but rather just 240. I'm not certain of this however.
And, is it given a filetype? .JPG, .GIF etc? If not, I'd say that is probably your problem.
Still not got to the cause :(
Posted: Mon Aug 06, 2007 9:43 am
by robshanks
Thanks again for your comments:
Again the images display fine in Firefox and IE7. They also print fine from Firefox, however, IE7 will not print them, nor do they show up with Print Preview.
Therefore, I am thinking that perhaps IE7 doesn't treat the image in the same way as Firefox - perhaps something to do with image caching on a https server? I am unsure as although I am an experienced programmer I am not experienced with the intricacies of web development for IE7.
It is in PHP so full line displaying the image is:
Code: Select all
echo "<td colspan='5'><img src='scripts/sig.php?q=".$vehicleid."!".$vcdate."&sid=".rand()."' height='80' width='240' /></td></td>";
The PHP script sig.php returns a jpeg of a signature captured as coordinate data:
Code: Select all
<?php
$q=$_GET["q"];
$qa=explode("!",$q);
//Get Signature Data
$sql="SELECT vcdata FROM vehiclecheck WHERE vehicleid='".$qa[0]."' AND vcdate='".$qa[1]."'";
$res=mysql_query($sql);
$row=mysql_fetch_array($res);
$vcdata=explode("|",$row['vcdata']);
$plot=$vcdata[16];
//Draw Signature
$im = @imagecreatetruecolor(240, 80)
or die("Cannot Initialize new GD image stream");
$black=imagecolorallocate($im, 1, 1, 1);
$bg=imagecolorallocate($im, 255, 255, 255);
imagefill($im, 0, 0, $bg);
$sigpos=0;
while($sigpos<strlen($plot))
{
$plotX=intval(hexdec(substr($plot,$sigpos,2)));
$plotY=intval(hexdec(substr($plot,$sigpos+2,2)));
if($plotY>127)
{
$plotXold=$plotX;
$plotYold=$plotY-128;
}
else
{
imageline($im,$plotXold,$plotYold,$plotX,$plotY,$black);
$plotXold=$plotX;
$plotYold=$plotY;
}
$sigpos=$sigpos+4;
}
// Turn on output buffering
ob_start();
imagejpeg($im);
header("Content-type: image/jpeg");
// Tell the browser the number of bytes in buffer
header("Content-Length: " . ob_get_length());
// Send the buffer to the browser
ob_end_flush();
// Free the memory
imagedestroy($im);
exit;
?>
Any ideas gratefully received.
Thanks in advance
Rob
Posted: Mon Aug 06, 2007 9:48 am
by iknownothing
I'm no Pro with GD, I actually have no idea what that code does apart from what your telling me, but just for a bit of Trial and Error, try this, just for fun:
Notice, I added .jpg (as I can't see anywhere where it is being used in your code) (change .jpg to whatever image type you are using if not .jpg)
Code: Select all
echo "<td colspan='5'><img src='scripts/sig.php?q=".$vehicleid."!".$vcdate."&sid=".rand().".jpg' height='80' width='240' /></td>";
I'm thinking IE as an issue with MIME type or something, but disregard this post if you feel I'm way off the mark.
Nope :(
Posted: Mon Aug 06, 2007 9:51 am
by robshanks

No difference - oh well will keep searching for inspiration.
Posted: Mon Aug 06, 2007 10:12 am
by onion2k
Doh. Need to learn to read.
Posted: Mon Aug 06, 2007 11:38 am
by Zoxive
Why not just get rid of the explode and make it another $_GET variable?
Code: Select all
echo "<img src='scripts/sig.php?id=".$vehicleid."&date=".$vcdate."&sid=".rand()."' height='80px' width='240px' />";
Posted: Mon Aug 06, 2007 12:17 pm
by robshanks
Thanks Zoxive
But the problem isn't producing the image, that is produced fine.
The only issue is IE7 will not print the image. IE7 displays it correctly, Firefox both displays it and prints it correctly.
Posted: Mon Aug 06, 2007 12:26 pm
by Zoxive
robshanks wrote:Thanks Zoxive
But the problem isn't producing the image, that is produced fine.
The only issue is IE7 will not print the image. IE7 displays it correctly, Firefox both displays it and prints it correctly.
Simplifying the script makes it easier to determine what is wrong.
Did you debug and echo all the variables you want your php code to see in IE7?
It could also be, because you are setting your headers after you send the image data.
Code: Select all
header("Content-type: image/jpeg");
imagejpeg($im); // Should be after Header
Posted: Mon Aug 06, 2007 2:24 pm
by robshanks
Thank you all for your assistance.
Zoxive put me on the right track: Simplifying it all down to basics worked:
Code: Select all
<?php
header("Content-type: image/jpeg");
$im = @imagecreatetruecolor(240, 80)
or die("Cannot Initialize new GD image stream");
$black=imagecolorallocate($im, 1, 1, 1);
$bg=imagecolorallocate($im, 255, 255, 255);
imagefill($im, 0, 0, $bg);
imagestring($im,3,1,1,"Help! Won't print in IE7",$black);
imagejpeg($im);
imagedestroy($im);
exit;
?>
So in my original code I pass the coordinate data directly rather than carrying out the mysql_query and it has worked and IE7 will now print the image
Thanks again.
Posted: Mon Aug 06, 2007 3:12 pm
by feyd
Make sure to also specify the content-length header....
Posted: Mon Aug 06, 2007 3:21 pm
by robshanks
Hehe
This is where it all started for me . . .
To specify the content-length header you have to buffer the output (as I am not saving the image as a file) which was the first thing I tried to get IE7 to print the image.
However, it is there in my production code:
Code: Select all
<?php
$plot=$_GET["q"];
$im = @imagecreatetruecolor(240, 80)
or die("Cannot Initialize new GD image stream");
$black=imagecolorallocate($im, 1, 1, 1);
$bg=imagecolorallocate($im, 255, 255, 255);
imagefill($im, 0, 0, $bg);
$sigpos=0;
while($sigpos<strlen($plot))
{
$plotX=intval(hexdec(substr($plot,$sigpos,2)));
$plotY=intval(hexdec(substr($plot,$sigpos+2,2)));
if($plotY>127)
{
$plotXold=$plotX;
$plotYold=$plotY-128;
}
else
{
imageline($im,$plotXold,$plotYold,$plotX,$plotY,$black);
$plotXold=$plotX;
$plotYold=$plotY;
}
$sigpos=$sigpos+4;
}
// Turn on output buffering
ob_start();
imagejpeg($im);
header("Content-type: image/jpeg");
// Tell the browser the number of bytes in buffer
header("Content-Length: " . ob_get_length());
// Send the buffer to the browser
ob_end_flush();
// Free the memory
imagedestroy($im);
exit;
?>
Zoxive wrote:
It could also be, because you are setting your headers after you send the image data.
PHP:
header("Content-type: image/jpeg");
imagejpeg($im); // Should be after Header
The image and the header are sent to the buffer and then the buffer is sent to the browser.
In the end it was something to do with the extra code I had in the script producing the image which was being used to access the database to retreive the coordinate data which was casuing the problem.
When i passed the coordinate data directly and only produce the image from it in the script it displays and prints correctly in Firefox and IE7.
Now I just need to check the max amount of data I can pass as a string via $_GET . . . but that'll wait for another day.
Posted: Mon Aug 06, 2007 3:25 pm
by feyd
It's typically a few kilobytes of data for most browsers, but does vary between operating systems and browsers.