Go Back   Web Hosting UK Forums | Linux Windows Dedicated Server and cPanel VPS Hosting Forum > Support > php issues.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-29-2006, 10:35 AM
Moderator
 
Join Date: Sep 2006
Posts: 629
Send a message via MSN to harry
Default PHP graphics help

In PHP for manipulating image files which is better function imagecopyresized() or imagecopyresampled(),
I know function imagecopyresampled() will resize the image but will also resample the image. What is this resampling of image, will it affect the quality of image if i use higher function values.
Reply With Quote
  #2 (permalink)  
Old 10-29-2006, 12:03 PM
kev woodman's Avatar
Premium Member
 
Join Date: Jul 2006
Location: Newport, Wales, UK.
Posts: 1,494
Default

I'd suggest using imagecopyresized() if you're not worried about the final quality e.g. if you're creating thumbnails on the fly. It's quick and dirty but it does the job.

If you want good quality images go for imagecopyresample(): you get more finegrained control over the eventual quality but you have to sacrifice some performance for it. Having said that unless the images are really large or your site is very very busy you probably won't notice the performance hit. I've used this function before and although I could spot the speed difference none of the apps users seemed bothered.
__________________
homo sum: humani nil a me alienum puto ... ( just Google it )
Reply With Quote
  #3 (permalink)  
Old 10-30-2006, 09:21 AM
Moderator
 
Join Date: Sep 2006
Posts: 629
Send a message via MSN to harry
Default

ken,thanks for suggestion.
please tell me, how would be the quality of image, if the image that i use is quit small and i use imagecopyresample() to make it large enough.
Reply With Quote
  #4 (permalink)  
Old 10-30-2006, 10:36 AM
sanderson's Avatar
Moderator
 
Join Date: Oct 2006
Location: Durham
Posts: 261
Default PHP Image Resizing

Dear One,
First up all you have not mention the specifications (It's a good practice) of the image, the most important thing to analyze the issue. If you haven't read this thread, http://www.webhosting.uk.com/forums/...read.php?t=672 I would recommend to read it first. Providing details information would be very useful to get help promptly. Lets come back to your question...
Quote:
what would be the quality of image, if the image that I use is quite small and I use imagecopyresample() to make it large enough.
<!--[if !supportLineBreakNewLine]-->
<!--[endif]-->
There are several probabilities depending on the resolution of the image. If the resolution of the image is high enough, I mean the pixels then small size would not be a major concern. Second, you will have to maintain the proportion of the image. Large enough means how big? 3,4,5… times bigger? I guess not more than double. IMHO if you take care of these two then, you won't need to worry about the quality.
Reply With Quote
  #5 (permalink)  
Old 10-30-2006, 11:19 AM
kev woodman's Avatar
Premium Member
 
Join Date: Jul 2006
Location: Newport, Wales, UK.
Posts: 1,494
Default

Sorry Harry I didn't realise you were resampling up.

If you're looking to make the image larger then the quality is going to pretty poor unless the size increase you're going for is very small. It all comes down to resolution - assuming your images are screen standard 72dpi then if you resize an image from 100px x 100px to 300px x 300px then you are lowering the dpi to a third which means each pixel is going to be three times larger resulting in a blocky image.

Intelligent resampling will look to offset this by sticking to 72dpi and guessing at the colour of the extra pixels it creates, based on the colour of the surrounding pixels. This is better than just scaling up but Photoshop struggles with this sort of thing so I'm guessing a PHP function is going to have no chance. Unfortunately the only time I've ever used it is to scale down or to change the aspect ratio of an image so I can't give you a definitive answer.

If you're only going up by a bit then I'd have a go. Let me know how you get on though because I'd be interested in the result.
__________________
homo sum: humani nil a me alienum puto ... ( just Google it )
Reply With Quote
  #6 (permalink)  
Old 10-30-2006, 11:42 AM
sanderson's Avatar
Moderator
 
Join Date: Oct 2006
Location: Durham
Posts: 261
Default

Quote:
This is better than just scaling up but Photoshop struggles with this sort of thing so I'm guessing a PHP function is going to have no chance.
Right. PHP is not at all for editing an image. Though if somebody uses it as a shortcut then it will look very patchy, unprofessional. The better option would be - to decide the size of the image first, enhance it with PhotoShop or any other Image editing software and then bring it to PHP.
Reply With Quote
  #7 (permalink)  
Old 10-30-2006, 12:03 PM
kev woodman's Avatar
Premium Member
 
Join Date: Jul 2006
Location: Newport, Wales, UK.
Posts: 1,494
Default

I'm guessing, but I think Harry probably wants to resize images on-the-fly - this is a useful function for a CMS for example - you can let users upoad images without them having to worry about resizing them. The you use PHP to resample/resize the image server-side.
__________________
homo sum: humani nil a me alienum puto ... ( just Google it )
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 01:22 PM.
Copyright 2002-2007 WebHosting.uk.com. All rights reserved.
Web Hosting UK Forum