Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    Aug 2002
    Location
    Oregon, United States of America
    Posts
    882
    Thanks
    1
    Thanked 9 Times in 9 Posts

    IE JPEG Save As problem with GD

    I am dynamicly creating a JPEG image with the GD library. The image is being called with an image tag with a souce of 'image.jpg' Htaccess is redircting that to image.php. That php page creates the image and prints it out, using these headers:

    PHP Code:
    header('Content-Disposition:  attachment;  filename="My_Swatch.jpg"');
    header("Cache-Control: no-cache, must-revalidate");
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    header("Content-Type: image/jpeg"); 
    In Firefox, if you right click the image and choose Save Image as... it defaults to a JPEG image named My_Swatch.jpg. However in IE if you do the same thing, it will default to untitled.bmp, and won't even let you try to save it as a JPEG file.

    I know this is in the header information and not the file name I am choosing to put in the source, or IE would use image.jpg as the file name, and it dosn't.

    Does anyone know what I need to do header-wise to make IE obey the name and file type that I send it?

    Thank you.

    Note: The image displays correctly in all browsers, I am simply trying to get Right Click -> Save As working. I always could make a Click To Download link, but I am worried that my users will still try to save it, or even copy and paste it into another application.
    If I'm postin here, I NEED YOUR HELP!!

  • #2
    Regular Coder
    Join Date
    Aug 2002
    Location
    Oregon, United States of America
    Posts
    882
    Thanks
    1
    Thanked 9 Times in 9 Posts
    [bump]

    I really need to get this working. I am worried that my users will try to copy and paste the image I am creating into and email, and it will not work, because IE can't recognise the file type, regarless of the header information and the URL i am using, (both saying jpeg.)

    If anyone needs more information to help me out, then by all means let me know. But I could really use the help on this one.
    If I'm postin here, I NEED YOUR HELP!!

  • #3
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,395
    Thanks
    8
    Thanked 1,078 Times in 1,069 Posts
    I just read something about your problem (what a coincidence).

    I think you need to utilize this:
    http://fr.php.net/session_cache_limiter

    That fixes the problem with IE not recognizing the Content-Type.
    Let me know if that helps you out.

    This is a quote for .gif ... but same as .jpg?

    Using <IMG SRC="image.php"> to dynamically generate images is a bit problematic regarding cache. Unless caching is activated, IE seems to get confused about the type of the image when attempting to save it. A .GIF created in the above way causes the browser to suggest saving the image with .BMP, not .GIF.

    A solution is to activate cache with session_cache_limiter('public'); in "image.php", after which IE will correctly save as .GIF. If you do not want the cache to block any changes in the dynamic image, make sure that the SRC keeps changing with every reload. Something like "image.php/" . mt_rand(1,100000) . ".gif" seems to work well.

    Might be trivial to some, but I spent a couple of hours figuring out why IE always wants to save my dynamic .GIF's as .BMP's.
    Last edited by mlseim; 01-22-2008 at 08:29 PM.

  • Users who have thanked mlseim for this post:

    Ultragames (01-22-2008)

  • #4
    Regular Coder
    Join Date
    Aug 2002
    Location
    Oregon, United States of America
    Posts
    882
    Thanks
    1
    Thanked 9 Times in 9 Posts
    Exactly what i was looking for!

    Thanks!
    If I'm postin here, I NEED YOUR HELP!!

  • #5
    Regular Coder
    Join Date
    Aug 2002
    Location
    Oregon, United States of America
    Posts
    882
    Thanks
    1
    Thanked 9 Times in 9 Posts
    Well that didn't seem to have an effect... I made sure to set teh cache limiter before starting the session, but it did not effect IEs handeling of the filename.

    Is there a change to my header information that I should make in addition the changing the cache limiter?

    Is there a content disposition besides attachment that I can use and still specify the file name?

    Is my cache control header conflicting with the cache limiter?

    Thanks!
    If I'm postin here, I NEED YOUR HELP!!

  • #6
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,395
    Thanks
    8
    Thanked 1,078 Times in 1,069 Posts
    Can you post the whole PHP script?

    Maybe I can try it on my server with a .jpg image and see what happens.

  • #7
    Regular Coder
    Join Date
    Aug 2002
    Location
    Oregon, United States of America
    Posts
    882
    Thanks
    1
    Thanked 9 Times in 9 Posts
    It refferences a lot of classes, and database information and GET variables and would very difficult for me to have someone else fully emulate. However I am fairly certain that you should be able to help with the following information:

    The image is being called using "image.jpg" but htaccess is redirecting the call to "image.php"

    And the following sumarized code:

    PHP Code:
    if( $cache_limiter session_cache_limiter( (string)$cache_limiter );
    session_start();

    list(
    $width$height) = getimagesize('__FILE_GOES_HERE__');

    ## Convert the Image to PNG-24
    $im_tc imagecreatetruecolor($width,$height);
    imagecopy($im_tc,$im,0,0,0,0,$width,$height);
    imagedestroy($im);
    $im $im_tc;

    $base_color = array(239,45,193);
    $base imagecreatetruecolor($width,$height);
    imagecopy($base,$im,0,0,0,0,$width,$height);
    imagelayereffect($baseIMG_EFFECT_OVERLAY);
    imagefilledrectangle($base00$width$heightimagecolorallocatealpha($base$base_color[0], $base_color[1], $base_color[2], 0));
    imagecopyresized($im$base0000$width$height$width$height);
    imagedestroy($base);

    header('Content-Disposition:  attachment;  filename="My_Swatch.jpg"'); 
    header("Cache-Control: no-cache, must-revalidate");
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    header("Content-Type: image/jpeg");
    imagejpeg($im);
    exit; 
    If I'm postin here, I NEED YOUR HELP!!

  • #8
    Regular Coder
    Join Date
    Aug 2002
    Location
    Oregon, United States of America
    Posts
    882
    Thanks
    1
    Thanked 9 Times in 9 Posts
    Also note: The images I am openeing are PNG images, but I am printing a JPEG image at the end of the script. From my understanding of the way GD works, that dosn't matter. But I may be wrong.
    If I'm postin here, I NEED YOUR HELP!!

  • #9
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,395
    Thanks
    8
    Thanked 1,078 Times in 1,069 Posts
    I'm beginning to see a lot of things like this:
    http://msmvps.com/blogs/spywaresucks.../21/63560.aspx

    As though this is a known IE problem and there's nothing you can do with scripting
    to fix this. Other blogs indicate the same thing ... an IE brower problem.

    I tested on my IE and I can right-click and save .png just fine, but not .jpg.

    Can you display as .png instead of .jpg?

  • #10
    Regular Coder
    Join Date
    Aug 2002
    Location
    Oregon, United States of America
    Posts
    882
    Thanks
    1
    Thanked 9 Times in 9 Posts
    Windows computers still do not have a good way of showing PNG images be default. Users usualy use IE which trys to launch Quicktime or the like, or they use Photoshop, but for the average user with a home install of XP, saving PNG images, or worse... trying to copy and paste them into an email, is just not a good idea.

    If you have MSDN evidence to prove me wrong by all means, I would enjoy learning otherwise.

    Thanks for the great links. For others who find this post through the search feature, check these links out:

    http://support.microsoft.com/default...b;en-us;810978
    http://support.microsoft.com/kb/q260650/
    If I'm postin here, I NEED YOUR HELP!!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •