Jump to content

PHP Image Resize


calvin182

Recommended Posts

What I want to do is I want to be able to let my site users take an image from their pc, upload it into a thumbnail (max 100x100). Then I want the broswer to display the resized image so the user can save it to their harddrive. I don't want to store the image on my server (unless its temporary and for like an hour tops). I've done some searching on google and can't find what I want, anybody know of any scripts that do this?

Link to comment
Share on other sites

Here is some code for resizing images. It comes from a program I wrote to automatically create galleries from a folder of images. Definately works for jpg. But I saved the thumbnails to my servers harddrive - you could ignore that part and use the imagedestroy function after you've displayed it. Hope this helps.if ($type == "jpg" || $type == "jpeg" || $type == "JPG" || $type == "JPEG"){ $img_source = imagecreatefromjpeg($this->path.$imagename); $oldWidth = imagesx($img_source); $oldHeight = imagesy($img_source); $newHeight = ($newWidth/$oldWidth)*$oldHeight; $img_destination = imagecreatetruecolor($newWidth,$newHeight); imagecopyresized($img_destination,$img_source,0,0,0,0,$newWidth,$newHeight,$oldWidth,$oldHeight); imagejpeg($img_destination,$this->options->thumb_path . "thumb" . $imagename,100); return $this->options->thumb_path . "thumb" . $imagename;}elseif ($type == "gif" || $type == "GIF"){ $img_source = imagecreatefromgif($this->path.$imagename); $oldWidth = imagesx($img_source); $oldHeight = imagesy($img_source); $newHeight = intval((doubleval($newWidth)/doubleval($oldWidth))*$oldHeight); $img_destination = imagecreate($newWidth,$newHeight); imagecopyresized($img_destination,$img_source,0,0,0,0,$newWidth,$newHeight,$oldWidth,$oldHeight); imagegif($img_destination,$this->options->thumb_path . "thumb" . $imagename); return $this->options->thumb_path . "thumb" . $imagename;}elseif ($type == "png" || $type == "PNG"){ $img_source = imagecreatefrompng($this->path.$imagename); $oldWidth = imagesx($img_source); $oldHeight = imagesy($img_source); $newHeight = intval((doubleval($newWidth)/doubleval($oldWidth))*$oldHeight); $img_destination = imagecreate($newWidth,$newHeight); imagecopyresized($img_destination,$img_source,0,0,0,0,$newWidth,$newHeight,$oldWidth,$oldHeight); imagepng($img_destination,$this->options->thumb_path . "thumb" . $imagename); return $this->options->thumb_path . "thumb" . $imagename;}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...