|
#1
|
|||
|
|||
|
hard code compresson level on resize?
Can some one advise me please? I'd like to hard code a compression level for a resize script using gd 201. Presently, a 1,800 kb file is typically reduced to 100 kb. Obviously, we're loosing a lot of detail.
Where? How? Thanks in advance. Code:
function resizeimage($args) {
$file = $args['file'];
$max_width = $args['max_width'];
$max_height = $args['max_height'];
define(IMAGE_BASE, "../images");
$image_path = IMAGE_BASE . "/$file";
$img = null;
$ext = strtolower(end(explode('.', $image_path)));
if ($ext == 'jpg' || $ext == 'jpeg') {
$img = @imagecreatefromjpeg($image_path);
} else if ($ext == 'png') {
$img = @imagecreatefrompng($image_path);
} else if ($ext == 'gif') {
$img = @imagecreatefromgif($image_path);
}
exec("cp " . $image_path . " " . $image_path . "_orig");
echo "$image_path";
if($img) {
$width = imagesx($img);
$height = imagesy($img);
$scale = min($max_width/$width, $max_height/$height);
if($scale < 1) {
$new_width = floor($scale*$width);
$new_height = floor($scale*$height);
$tmp_img = imagecreatetruecolor($new_width,$new_height);
if(function_exists(imagecopyresampled)) {
imagecopyresampled($tmp_img, $img, 0,0,0,0,$new_width,$new_height,$width,$height);
} else {
imagecopyresized($tmp_img, $img, 0,0,0,0,$new_width,$new_height,$width,$height);
}
imagedestroy($img);
$img = $tmp_img;
}
}
|
|
#2
|
||||
|
||||
|
are you talking about resize of thumbnails? because you can change the compression level in the admin panel for that.
__________________
Affordable Website Design in North Wales |
|
#3
|
|||
|
|||
|
Nope. Well, almost.
The above code is utok's hack/mod to resize and make wallpapers. It is a rework of the thumbnail code. That said, I just cannot tell if it is also utilizing the thumbnails compression ratio. And if it is, where? Or, might there be default limitations set by my hosting company? Thoughts? |
|
#4
|
|||
|
|||
|
imagejpeg($img, "../images/$file",100);
|
| Post Reply |
| Thread Tools | |
|
|