Saving of Dynamically Created Images

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
Toasty
-


Joined: 21 Feb 2008
Posts: 298
Location: Chicago, IL

PostPosted: Sun Mar 30, 2008 1:43 am    Post subject: Saving of Dynamically Created Images Reply with quote

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 View user's profile Send private message Visit poster's website
pkSML
-


Joined: 29 May 2006
Posts: 952
Location: Michigan, USA

PostPosted: Sun Mar 30, 2008 2:18 am    Post subject: Reply with quote

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 View user's profile Send private message Visit poster's website
Toasty
-


Joined: 21 Feb 2008
Posts: 298
Location: Chicago, IL

PostPosted: Sun Mar 30, 2008 3:03 am    Post subject: Reply with quote

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 View user's profile Send private message Visit poster's website
Tom Chapman
-


Joined: 09 Jul 2005
Posts: 933
Location: Australia

PostPosted: Sun Mar 30, 2008 12:51 pm    Post subject: Reply with quote

HAHAHAHA!.. nice speed test Toasty ;- )
Back to top View user's profile Send private message Visit poster's website MSN Messenger
pkSML
-


Joined: 29 May 2006
Posts: 952
Location: Michigan, USA

PostPosted: Sun Mar 30, 2008 5:12 pm    Post subject: Reply with quote

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 View user's profile Send private message Visit poster's website
Toasty
-


Joined: 21 Feb 2008
Posts: 298
Location: Chicago, IL

PostPosted: Sun Mar 30, 2008 9:39 pm    Post subject: Reply with quote

Tom wrote:
HAHAHAHA!.. nice speed test Toasty ;- )


lol, thanks!


pkSML -- Thanks for the code -- I'll give that a shot.
_________________
Audit the secure configuration of your server headers!
Back to top View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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


Powered by phpBB phpBB Group