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
can i optmize image to 50% quality before uploading 2 server
Moderator: General Moderators
-
ryanfern86goa
- Forum Newbie
- Posts: 16
- Joined: Tue Sep 22, 2009 5:26 pm
Re: can i optmize image to 50% quality before uploading 2 server
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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
-
ryanfern86goa
- Forum Newbie
- Posts: 16
- Joined: Tue Sep 22, 2009 5:26 pm
Re: can i optmize image to 50% quality before uploading 2 server
hi pickle
thanks for your reply...
appreciated...
thanks for your reply...
appreciated...
- SimpleManWeb
- Forum Commoner
- Posts: 57
- Joined: Wed Dec 30, 2009 4:15 pm
- Location: New Hampshire, USA
Re: can i optmize image to 50% quality before uploading 2 server
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:
I didn't test this code, but it should work.
Hope this helps
Your code was close, try this:
Code: Select all
$Directory = "../Images/ImageName.jpg";
$Quality = 50;
$Image = imagecreatefromjpeg($Directory);
imagejpeg($Image, $Directory, $Quality);
Hope this helps