Fixed #1152: Needless image scaling and poor JPG quality

This commit is contained in:
Sean Murphy 2009-02-07 10:01:08 -05:00
parent d6245dca63
commit d900893149

View File

@ -113,6 +113,23 @@ class ImageFile
return; 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) { switch ($this->type) {
case IMAGETYPE_GIF: case IMAGETYPE_GIF:
$image_src = imagecreatefromgif($this->filepath); $image_src = imagecreatefromgif($this->filepath);
@ -165,7 +182,7 @@ class ImageFile
imagegif($image_dest, $outpath); imagegif($image_dest, $outpath);
break; break;
case IMAGETYPE_JPEG: case IMAGETYPE_JPEG:
imagejpeg($image_dest, $outpath); imagejpeg($image_dest, $outpath, 100);
break; break;
case IMAGETYPE_PNG: case IMAGETYPE_PNG:
imagepng($image_dest, $outpath); imagepng($image_dest, $outpath);
@ -175,6 +192,9 @@ class ImageFile
return; return;
} }
imagedestroy($image_src);
imagedestroy($image_dest);
return $outname; return $outname;
} }