summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSean Murphy <sgmurphy@gmail.com>2009-02-07 10:01:08 -0500
committerSean Murphy <sgmurphy@gmail.com>2009-02-07 10:01:08 -0500
commitd90089314944ed1696f66cabbb6935ea61e4b2e6 (patch)
treee7355e0e22f95b00a60708908334e39cd83f58fd /lib
parentd6245dca6347a670445701e9c726b0719ea945c8 (diff)
Fixed #1152: Needless image scaling and poor JPG quality
Diffstat (limited to 'lib')
-rw-r--r--lib/imagefile.php22
1 files changed, 21 insertions, 1 deletions
diff --git a/lib/imagefile.php b/lib/imagefile.php
index 74c3d14f0..faec7f0ff 100644
--- a/lib/imagefile.php
+++ b/lib/imagefile.php
@@ -112,6 +112,23 @@ class ImageFile
throw new Exception(_('Lost our file.'));
return;
}
+
+ // Don't crop/scale if it isn't necessary
+ if ($size === $this->width
+ && $size === $this->height
+ && $x === 0
+ && $y === 0
+ && $w === $this->width
+ && $h === $this->height) {
+
+ $outname = common_avatar_filename($this->id,
+ image_type_to_extension($this->type),
+ $size,
+ common_timestamp());
+ $outpath = common_avatar_path($outname);
+ @copy($this->filepath, $outpath);
+ return $outname;
+ }
switch ($this->type) {
case IMAGETYPE_GIF:
@@ -165,7 +182,7 @@ class ImageFile
imagegif($image_dest, $outpath);
break;
case IMAGETYPE_JPEG:
- imagejpeg($image_dest, $outpath);
+ imagejpeg($image_dest, $outpath, 100);
break;
case IMAGETYPE_PNG:
imagepng($image_dest, $outpath);
@@ -174,6 +191,9 @@ class ImageFile
throw new Exception(_('Unknown file type'));
return;
}
+
+ imagedestroy($image_src);
+ imagedestroy($image_dest);
return $outname;
}