Page 1 of 1

can i optmize image to 50% quality before uploading 2 server

Posted: Sat Jan 09, 2010 9:13 am
by ryanfern86goa
Hi there

i have jus written a php program to upload and display images but when i try to upload them it takes a long time to upload if the file is big. But the big problem is when i try to display them. The time taken to display them is huge. so i was just wondering if its posible to optimize a image before uploading it to the server and also save some bandwidth. can i do this directly from the upload form for jpeg image

$name=$_FILES['file']['name'];
$tmpname=$_FILES['file']['tmp_name'];
$path=images/$name;
$tmp=imagecreatefromjpeg($tmpname);
imagejpeg($tmp,$path,50);

Any comments would be grately be appreciated.

thanks

Re: can i optmize image to 50% quality before uploading 2 server

Posted: Mon Jan 11, 2010 11:08 am
by pickle
Using HTML/Javascript/PHP, there is no way to optimize the image before uploading. To do that you'll need a Java applet or Flash file. SWFUpload provides just that functionality in their latest beta.

Re: can i optmize image to 50% quality before uploading 2 server

Posted: Mon Jan 11, 2010 4:37 pm
by ryanfern86goa
hi pickle

thanks for your reply...

appreciated...

Re: can i optmize image to 50% quality before uploading 2 server

Posted: Mon Jan 11, 2010 6:33 pm
by SimpleManWeb
You can however optimize it AFTER you upload it which means that at least your images will load faster on your site. You need to have the GD library installed on your server, which most hosting companies already provide.

Your code was close, try this:

Code: Select all

 
        $Directory = "../Images/ImageName.jpg";
        $Quality = 50;
        $Image = imagecreatefromjpeg($Directory);
    imagejpeg($Image, $Directory, $Quality);
 
I didn't test this code, but it should work.

Hope this helps