Jump to content

Recommended Posts

I have 2 problems with displaying images directly to the browser:

1) I have worked out how to display the image:
[code]$filename='testimage.jpg';
header ('Content-Type: image/jpeg');
imagejpeg($filename);[/code]

No problem there, it works great, the image is displayed just as it should be. But, when I try to save the jpg image I can only save it as a BMP file!! For some reason the browser doesn't recognise that it is a jpg file. It is happening to other people as well, so it's not a local computer problem.

2) My second problem is that the displayed image (when saved) is a different resolution to the original. The original image has a 300dpi resolution. Why does this change when the image is displayed in this style?? When I use a normal IMG tag to display the jpg it retains the 300dpi resolution.

Any help would be greatly appreciated as this is driving me nuts ???
Link to comment
https://forums.phpfreaks.com/topic/33459-image-displaysave-as-problem/
Share on other sites

whilst it might not solve the problem, lets try getting things into the "normal" way of doing things. [url=http://uk2.php.net/imagejpeg]imagejpeg[/url] (function) takes 3 parameters - the 'resouce', a '[b]destination[/b]' filename, and a 'quality' setting.

[code]
<?php
$im = imagecreatefromjpeg('testimage.jpg');

header('Content-type: image/jpeg');
imagejpeg($im);
?>
[/code]

the default quality setting for imagejpeg is 75%. if you want higher, use (for example)

[code]
imagejpeg($im, '', 90);
[/code]

have you tried this on a different browser yourself, just to make sure that its not an issue of what the browser is set to accept?
I've changed the code to:
[code]$im = imagecreatefromjpeg($filename);
header('Content-type: image/jpeg');
imagejpeg($im,'',100);[/code]

Where $filename comes from a MySQL table.
I've tried it in IE6 and Firefox, both browsers display the image perfectly. However, IE only lets me save it as a BMP file. Firefox on the otherhand wants to save the php file (downloadimage.php). If I try saving it as a .jpg it won't open in graphics programs. However, atleast with firefox I have the ability to copy image which works.

Am I missing something or what? I've been through all the tutorials I can find and they all seem to work.
MMCB
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.