Forum Moderators: coopster

Message Too Old, No Replies

Resize and Reduce the image size in a proper ratio

my function resize image but doesnt reduce its size

         

phparion

6:01 pm on Nov 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi

I am using following function to resize an image based on a specific ratio

function imageResize($width, $height, $target) {

if ($width > $height) {
$percentage = ($target / $width);
}

else {
$percentage = ($target / $height);
}

$width = round($width * $percentage);
$height = round($height * $percentage);

return "width=\"$width\" height=\"$height\"";
}

but this doesnt reduce the size of the image e.g if an image is 400 x 500 and its size is 400 KB, my function will reduce its dimensions but its size remain same 400 KB .. so half of the job is done..

can anyone help please or is there any other function that not only reduce dimensions but also the size of the image?

thanks

barns101

6:18 pm on Nov 7, 2006 (gmt 0)

10+ Year Member



I'm no expert regarding resizing images with PHP, but I know that you can set the image quality. Perhaps your script is setting the image quality to 100% and that would account for a smaller file (in dimensions) but no reduction in file size? Take a look at the PHP manual for the functions that you're using and check image quality.

eelixduppy

8:10 pm on Nov 7, 2006 (gmt 0)



You aren't actually resizing the image itself, you are just displaying it with different dimensions within the img tag.

Your best bet is to reduce them before you put them on the server, or if you are allow user uploads or something like that, then you can use php's image functions [us3.php.net] to resize it on upload, and then just display the resized image.

phparion

4:04 am on Nov 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I was wondering if there is any possibility to reduce dimensions as well as size of an image in real time that is on my server , because my users upload images and i need them in different sizes in different places so cant afford to copy five or six copies of a single image because if there are 10 000 users it means 10 000 x 6 images on server ...

thanks

eelixduppy

8:04 am on Nov 10, 2006 (gmt 0)



How many different image sizes are we talking about here?

I think if you resize the uploaded image to an average size of all the images sizes that you'll need, you can then resize them like you did in your previous post making the image larger or smaller depending on what you need.