Page 1 of 1
Which is best... Image resizing functions.
Posted: Thu Oct 11, 2007 3:02 pm
by JellyFish
Which is the better image resizing function: imagecopyresized() or imagecopyresampled()? Better as in results in a more clear, more accurate resized image?
I'm looking to resize an uploaded image, and I'm sure I'm not the first to be asking question about this. So any tips would be great!
Thanks.
Posted: Thu Oct 11, 2007 3:13 pm
by VladSun
A look at the PHP manuals shows that the only difference is this sentence:
"smoothly interpolating pixel values so that, in particular, reducing the size of an image still retains a great deal of clarity"
So, my guess is that imagecopyresampled() would give better image quality.
I can't imagine how an image resizing can be done without any interpolation, but maybe imagecopyresampled() uses higher interpolation order than imagecopyresized().
Posted: Thu Oct 11, 2007 3:26 pm
by JellyFish
VladSun wrote:A look at the PHP manuals shows that the only difference is this sentence:
"smoothly interpolating pixel values so that, in particular, reducing the size of an image still retains a great deal of clarity"
So, my guess is that imagecopyresampled() would give better image quality.
I can't imagine how an image resizing can be done without any interpolation, but maybe imagecopyresampled() uses higher interpolation order than imagecopyresized().
Yeah, that's kinda what I thought.
Also, if I'm going to resize an uploaded image then I guess this wouldn't work anymore:
Code: Select all
move_uploaded_file($_FILES['image']['tmp_name'],"/LOCATION/".$_FILES['image']['name']);
right? I'm assuming that move_uploaded_file() only works with uploaded image resources ($_FILES['image']['tmp_name']), rather then a resource that would be returned by imagegif() or something.
Posted: Thu Oct 11, 2007 5:37 pm
by pickle
1)
imagecopyresampled() makes a much better image than
imagecopyresized().
http://www.phpgd.com/articles.php?article=8&page=1 wrote:There is also a quicker option to resize the image. PHP's imagecopyresized() function is a lot faster, and less CPU intensive than imagecopyresampled(). However, it uses a basic 'Nearest Neighbour' algorithm so the results look blocky and poor quality.
http://www.phpgd.com/articles.php?article=8&page=1
2)
move_uploaded_file() only works on newly uploaded files. You want to use the
rename() function on files that haven't been newly uploaded.
Posted: Thu Oct 11, 2007 6:56 pm
by JellyFish
pickle wrote:
2)
move_uploaded_file() only works on newly uploaded files. You want to use the
rename() function on files that haven't been newly uploaded.
Why do I have to use move_uploaded_file() in particular? Isn't there another function that would take a newly created image and save it to a directory?
Posted: Thu Oct 11, 2007 10:02 pm
by Kieran Huggins
if memory serves, imagecopyresampled() creates a new colour index when you're dealing with indexed formats. imagecopyresized() uses the same colour map (which is often U-G-L-Y)
Posted: Fri Oct 12, 2007 9:51 am
by pickle
Well, there are the various image creation functions.