Image Resizing/Saving

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Image Resizing/Saving

Post by Steveo31 »

Got the resize part down, but I'm curious to the script for saving the resized image in a folder that I specify. I have a feeling that it's in the ImageCopyResized or ImageJpeg functions, but I couldn't find anything. What I am doing is having a user upload an image of a product and from there create a thumbnail. Then, save the thumb in a folder as well as the original, or at least a resized of the original (so people dont post 30mb images).

Thanks for any links or whatnot!
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

instead of echo'ing it out... just fwrite it to a file ;) and handling file uploads has been explained many times before in this forum
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

imageJpeg

Post by phpScott »

depending on what format you are using to create the smaller image use.
imageJpeg($handel, 'location and name');
manual page
[php_man]imagejpeg[/php_man]
The filename argument is optional, and if left off, the raw image stream will be output directly.
just use the write image(format);
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

timvw wrote:instead of echo'ing it out... just fwrite it to a file ;) and handling file uploads has been explained many times before in this forum
I'll give er a try. And... it's not the uploading I'm inquiring about, it's another thing entirely ;)

Thanks for the replies :)

Edit: Little bit of tinkering and came up with this:

Code: Select all

$thumb_ = explode(".", $_FILES['image_path']['name']);
$thumb_name = $thumb_[0];
$thumb_path = "members/".$_SESSION['username']."/".($thumb_name."_thumb.jpg");
ImageJpeg($dst, "$thumb_path", 100);
May be dirty, but works for me :lol:
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

what I said

Post by phpScott »

that's what i said.
the manual is your friend.
Post Reply