moment17
03-15-2006, 03:14 AM
I wasn't happy with the quality of admin_resize even at 100%, so I did a quick and dirty function and added to to the bottom of functions.php:
function maxSize($image_width, $image_height, $max_width, $max_height) {
$orientation = ($image_width >= $image_height) ? "landscape" : "portrait";
if ($orientation == "landscape") {
$factor = $image_height / $image_width;
} else {
$factor = $image_width / $image_height;
}
while ($image_width > $max_width || $image_height > $max_height) {
if ($orientation == "landscape") {
// width;
$image_height = round(($image_width * $factor));
if ($image_width > $max_width || $image_height > $max_height) {
$image_width = round($image_width - 5);
$image_height = round(($image_width * $factor));
}
} else {
// height;
$image_width = round(($image_height / $factor));
if ($image_width > $max_width || $image_height > $max_height) {
$image_height = round($image_height - 5);
$image_width = round(($image_height * $factor));
}
}
}
$img = array($image_width, $image_height);
return $img;
}
and in index.php down about line 253 (just below $image_width = $image_extra['0']; and $image_height = $image_extra['1'];) add:
$max_width = 790;
$max_height = 590;
$arSize = maxSize($image_width, $image_height, $max_width, $max_height);
and replaced $image_width and $image_height with the returned array vars in the following lines:
$tpl = str_replace("<IMAGE_WIDTH>",$image_width,$tpl);
$tpl = str_replace("<IMAGE_HEIGHT>",$image_height,$tpl);
to:
$tpl = str_replace("<IMAGE_WIDTH>",$arSize[0],$tpl);
$tpl = str_replace("<IMAGE_HEIGHT>",$arSize[1],$tpl);
I'm sure there's somepalce better for $max_width and $max_height (like in the database) but I just wanted to "set it and forget it" for the time being.
This works very well for me and takes little cpu on an old PIII/700 server running fedora. It also has the advantage that if you change your template to one with a different size image area you aren't stuck with a bunch of ill-fitting images.
function maxSize($image_width, $image_height, $max_width, $max_height) {
$orientation = ($image_width >= $image_height) ? "landscape" : "portrait";
if ($orientation == "landscape") {
$factor = $image_height / $image_width;
} else {
$factor = $image_width / $image_height;
}
while ($image_width > $max_width || $image_height > $max_height) {
if ($orientation == "landscape") {
// width;
$image_height = round(($image_width * $factor));
if ($image_width > $max_width || $image_height > $max_height) {
$image_width = round($image_width - 5);
$image_height = round(($image_width * $factor));
}
} else {
// height;
$image_width = round(($image_height / $factor));
if ($image_width > $max_width || $image_height > $max_height) {
$image_height = round($image_height - 5);
$image_width = round(($image_height * $factor));
}
}
}
$img = array($image_width, $image_height);
return $img;
}
and in index.php down about line 253 (just below $image_width = $image_extra['0']; and $image_height = $image_extra['1'];) add:
$max_width = 790;
$max_height = 590;
$arSize = maxSize($image_width, $image_height, $max_width, $max_height);
and replaced $image_width and $image_height with the returned array vars in the following lines:
$tpl = str_replace("<IMAGE_WIDTH>",$image_width,$tpl);
$tpl = str_replace("<IMAGE_HEIGHT>",$image_height,$tpl);
to:
$tpl = str_replace("<IMAGE_WIDTH>",$arSize[0],$tpl);
$tpl = str_replace("<IMAGE_HEIGHT>",$arSize[1],$tpl);
I'm sure there's somepalce better for $max_width and $max_height (like in the database) but I just wanted to "set it and forget it" for the time being.
This works very well for me and takes little cpu on an old PIII/700 server running fedora. It also has the advantage that if you change your template to one with a different size image area you aren't stuck with a bunch of ill-fitting images.