View previous topic :: View next topic |
Author |
Message |
Toasty -
Joined: 21 Feb 2008 Posts: 298 Location: Chicago, IL
|
Posted: Sun Mar 30, 2008 1:43 am Post subject: Saving of Dynamically Created Images |
|
|
I'm working on this Image Resizer script. It works great, only issue is when you go to save the file.
Because it is dynamically generated (I send the content-type before the actual output), when users go to save the file, it saves as "image_resize.html", as opposed to the ____.png (which it should save as).
Any ideas on how I can make it output it as a PNG that people can save? Or do I have to do a URI Rewrite/Actually Save the file.
Thanks for any feedback. _________________ Audit the secure configuration of your server headers! |
|
Back to top |
|
|
pkSML -
Joined: 29 May 2006 Posts: 952 Location: Michigan, USA
|
Posted: Sun Mar 30, 2008 2:18 am Post subject: |
|
|
I'm thinking you would make the resize script save the image locally to your server. Then on the HTML page you output, have <img src="/path/to/image/file.jpg">. That's just one way to do it.
I tried the script with a jpg and a png file, but it keeps telling me Quote: | An Error has occured. Please try again later.
MIME=Invalid |
---------------
If you use a PHP script to output the image file, rather than just directly pointing to the image file in your HTML, make the img tag as so: <img src="/show_image.php/filename.jpg">
Then when the user goes to save the pic, it'll save as filename.jpg.
You can see this in action at http://pksml.net/antipixel_ajax
Check out the image locations. (I use URL rewriting to do it, but that's not necesssary.) _________________ Stephen
Need a LitlURL?
http://CodeBin.yi.org |
|
Back to top |
|
|
Toasty -
Joined: 21 Feb 2008 Posts: 298 Location: Chicago, IL
|
Posted: Sun Mar 30, 2008 3:03 am Post subject: |
|
|
I'm curious as to why I'm getting MIME issues...I'm getting those on my other site for avatars too...
Code: |
$srcsize = @getimagesize("imageresize/" . $ID);
if ($srcsize['mime']=="image/jpeg")
{
$src_img = imagecreatefromjpeg("imageresize/" . $ID);
}
|
Also, do you know of the GD function to save the output from this, as opposed to storing it as a variable (thinking fwrite as I'm doing this...)
Code: | imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dest_x, $dest_y, $srcsize[0], $srcsize[1]); |
_________________ Audit the secure configuration of your server headers! |
|
Back to top |
|
|
Tom Chapman -
Joined: 09 Jul 2005 Posts: 933 Location: Australia
|
Posted: Sun Mar 30, 2008 12:51 pm Post subject: |
|
|
HAHAHAHA!.. nice speed test Toasty ;- ) |
|
Back to top |
|
|
pkSML -
Joined: 29 May 2006 Posts: 952 Location: Michigan, USA
|
Posted: Sun Mar 30, 2008 5:12 pm Post subject: |
|
|
Toasty wrote: | Also, do you know of the GD function to save the output from this, as opposed to storing it as a variable (thinking fwrite as I'm doing this...)
Code: | imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dest_x, $dest_y, $srcsize[0], $srcsize[1]); |
|
To store a file on the hard disk deals with either the imagejpeg or imagepng function.
Code: | imagejpeg($image_p, null, 100); |
The three function arguments are:
image source, filename, jpeg quailty
Imagepng only has two arguments, as it has no quality parameter. _________________ Stephen
Need a LitlURL?
http://CodeBin.yi.org |
|
Back to top |
|
|
Toasty -
Joined: 21 Feb 2008 Posts: 298 Location: Chicago, IL
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|