I need the ability to resize images already on my server, not during an upload. I already know how to copy an image to another folder, now I need to reduce it to 90wx63h and save it at that size. I'm sorry if this is an easy question, but I'm not very good at functions and when I read a lot of the articles on the topic I get lost real easy.
-- James
Resize images
Moderator: General Moderators
What you do is use the imagecopyresized() php function. Description on this function is available at php.net.
Something like:
Something like:
Code: Select all
$file_source = 'test.jpg';
// Content type
header('Content-type: image/jpeg');
// Get new sizes
list($width, $height) = getimagesize($file_source);
$newwidth = $width * $percent;
$newheight = $height * $percent;
// Load
$resized_img = imagecreatetruecolor($newwidth, $newheight);
$source_img = imagecreatefromjpeg($file_source);
// Resize
imagecopyresized($resized_img, $source_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
// Outputs the resized image to the browser
imagejpeg($resized_img);
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
instead use imagecopyresampled() so your pictures don't look like crap - I have no idea why this isn;t the default behaviour of imagecopyresized().
imagecopyresampled() copies a rectangular portion of one image to another image, smoothly interpolating pixel values so that, in particular, reducing the size of an image still retains a great deal of clarity.
- stereofrog
- Forum Contributor
- Posts: 386
- Joined: Mon Dec 04, 2006 6:10 am
Resizing an Image
This article will answer most of your questions.
http://www.universalwebservices.net/web ... e-with-php
http://tools.universalwebservices.net/resize-image/
http://www.universalwebservices.net/web ... e-with-php
http://tools.universalwebservices.net/resize-image/
Re: Resizing an Image
I don't understand. What's different? Is it because the quality parameter was set in the imagejpeg() function?lanasa wrote:This article will answer most of your questions.
http://www.universalwebservices.net/web ... e-with-php
http://tools.universalwebservices.net/resize-image/