Re: dynamic image will not print properly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I just wanted to add something to this....

I moved the script over to another host to test, and it worked fine there. So to me that says it should be something to do with the host... now is there anything in the php.ini that could inflict this kind of behavior?

d


On 5-Apr-05, at 5:57 PM, Richard Lynch wrote:

On Tue, April 5, 2005 2:26 pm, DuSTiN KRySaK said:
Hi there - I had my first crack at creating a dynamic image. The thing
is - the image is displayed fine in the browser, but when you go to
print it, the image is either missing, or part of it is missing. Is
there something special needed to print a dynamic image?

What you did, *should* work just fine.

But we're talking *MICROSOFT* here!

These people do *NOT* follow standards.  Period.

Here is a code snippet used to create the image....

header("Content-type: image/jpg");
$image = imagecreatefromjpeg("template_cpn.jpg");
$red = imagecolorallocate( $image, 255,0,0 );
imagestring($image, 2, 306, 200, $couponcode, $red);
imagestring($image, 2, 306, 235, $exp, $red);
imagestring($image, 2, 175, 338, $myname, $red);
imagestring($image, 2, 175, 360, $myemail, $red);
imagejpeg($image);
imagedestroy($image);

Now the way I have it set up, is that there is a PHP file that
generates the image (the above code). Then I have a parent PHP page
that calls that page like so:

$theurl = "cstl.php?dk=soemthinghere
echo "<img src=\"$theurl\">";

See any issues in my code or setup?

Any ideas?

Here's what you do: You make it *IMPOSSIBLE* for Microsoft to screw up.


This means you make your URL look JUST LIKE any other JPEG URL.

$theurl = "cstl/dk=somethinghere/whatever.jpg";

Step 1:
Add/Create an .htaccess file with this:
<Files cstl>
  ForceType application/x-httpd-php
</Files>
This forces Apache to treat the file named 'cstl' as a PHP script.

Step 2:
Rename cstl.php to just 'cstl' (see Step 1)

Step 3:
Instead of using $_GET['dk'] do this:
$pathinfo = $_SERVER['PATH_INFO'];
$pathinfo = explode('/', $pathinfo);
//Key-Value pairs:
$_PATH = array();
//Path information buried in URL for source image sub-directories:
$PATH = array();
while (list(, $keyval) = each($pathinfo)){
  $parts = explode('=', $keyval);
  switch(count($parts)){
    case 0: break; //do nothing with bogus extra '/' in URL
    case 1: $PATH[] = $keyval;
    default:
      $key = $parts[0];
      unset($parts[0]);
      $_PATH[$key] = implode('=', $parts);
    break;
  }
}

Now you can use $_PATH['dk'] instead of $_GET['dk'] to get your dk value
from the URL. You'll only change $_GET to $_PATH in cstl (formerly
cstl.php) and you're all set.


Now, there is *NO* *WAY* Microsoft can manage to screw up your URL and
decide that it must not be a JPEG because it has GET data, or ends in .php
or whatever.


This same technique must be applied to PDF, FDF, SWF/Ming files if you
want to avoid a zillion MS IE bugs related to multi-media.

So you might as well put the code for $_PATH/$PATH in an include file. I
guarantee you'll need it again and again as you use more and more
multi-media in your web-site.


--
Like Music?
http://l-i-e.com/artists.htm


-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux