SitePoint Sponsor |
|
User Tag List
Results 1 to 11 of 11
Thread: Reducing the size of an image
-
May 12, 2003, 10:32 #1
- Join Date
- Oct 2002
- Posts
- 229
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Reducing the size of an image
Hi,
Does anyone know if PHP can compress an image. I have a site where by users can upload images of themselves to be displayed in their profile. But I want to know if it is possible to compress it. Ie if they upload a 400kb photo, can I reduce this at all?
KjcEternity
-
May 13, 2003, 01:32 #2
- Join Date
- Aug 2001
- Location
- lost, If you find me please return me to St.Louis
- Posts
- 396
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
you could use GD or image magick & make it thumbnail all images over a certain size.
That would help make sure all images are say...less than 500x500 so they don't cause huge pictures to need scroll bars & file size (weight) would be reduced at the same time.You smell something?
-
May 13, 2003, 01:44 #3
- Join Date
- Mar 2001
- Location
- London | UK
- Posts
- 1,140
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Using the image functions, you can resize, crop, and otherwise manipulate the image. You can also pass a second paramater to imagejpeg() to specify the jpeg compression quality (if you want to use jpegs).
Regards,
Matt.
-
May 13, 2003, 07:53 #4
- Join Date
- Aug 2001
- Location
- Amsterdam
- Posts
- 788
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by kjc
PHP Code:function resize($image, $thumb, $x, $y, $type) {
$rat = 150; // the max length (or width)
$success = 0;
if($type == "jpg" ) {
$src = ImageCreateFromJpeg($image);
}
elseif($type == "gif" ) {
$src = ImageCreateFromGif($image);
}
if ($x > $y) {
$imagey = ceil(($rat * $y) / $x);
$imagex = $rat;
}
if ($y > $x) {
$imagex = ceil(($rat * $x) / $y);
$imagey = $rat;
}
if ($y == $x) {
$imagex = $rat;
$imagey = $rat;
}
$dst_img=ImageCreateTrueColor($imagex,$imagey);
ImageCopyResized($dst_img,$src,0,0,0,0,$imagex,$imagey,$x,$y);
if($type == "jpg" ) {
ImageJpeg($dst_img, $thumb);
$success = 1;
chmod($thumb, 0644);
}
elseif($type == "gif" ) {
ImageGif($dst_img, $thumb);
$success = 1;
}
return $success;
}
the neigbours (free) WIFI makes it just a little more fun
-
May 13, 2003, 08:15 #5
- Join Date
- Oct 2002
- Location
- Scotland
- Posts
- 3,631
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Here is a thumbnail script I created ... you use it by simply passing the filepath and desired width to it in an <img> tag ... e.g. ...
Code:<img src="thumbnail.php?src=/path/to/image.jpg&maxw=400" />
-
May 13, 2003, 17:03 #6
- Join Date
- May 2003
- Location
- canada
- Posts
- 29
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Peanuts, your fuunction would be useful to me, but I have a question. When I run the function on an image the exif data is lost. Is it possible to create the new images and keep the exif data?
-
May 14, 2003, 01:20 #7
- Join Date
- Aug 2001
- Location
- Amsterdam
- Posts
- 788
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by alt-f4
the neigbours (free) WIFI makes it just a little more fun
-
May 14, 2003, 01:23 #8
- Join Date
- May 2003
- Location
- canada
- Posts
- 29
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I guess sometimes I just need to know if it is possible.
That gives me one more thign to do thanks a lot
Scott
-
May 14, 2003, 12:09 #9
- Join Date
- Oct 2002
- Posts
- 229
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks for your replies. I will try it out in the next fews day and get back to you with the results.
CheersEternity
-
May 15, 2003, 10:29 #10
- Join Date
- Oct 2002
- Posts
- 229
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Are there any solutions which don't require GD to be installed. My web host doesn't have GD...
Eternity
-
May 15, 2003, 17:21 #11
what about image magick? by the way... are there any discussions about IM at the moment?
Bookmarks