|
#1
|
|||
|
|||
|
A better image resize
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:
Code:
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;
}
Code:
$max_width = 790; $max_height = 590; $arSize = maxSize($image_width, $image_height, $max_width, $max_height); Code:
$tpl = str_replace("<IMAGE_WIDTH>",$image_width,$tpl);
$tpl = str_replace("<IMAGE_HEIGHT>",$image_height,$tpl);
Code:
$tpl = str_replace("<IMAGE_WIDTH>",$arSize[0],$tpl);
$tpl = str_replace("<IMAGE_HEIGHT>",$arSize[1],$tpl);
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. |
|
#2
|
|||
|
|||
|
Quote:
__________________
http://se.nsuo.us - A photoblog of sensual, abstract nudes [may not be work safe for some] My Pixelpost Addons, Cheesecake-Photoblog Software |
|
#3
|
|||
|
|||
|
Quote:
The problem it solves is that it sets the image size using the img tag width and height properties, as does PP, but it also limits the maximum width and height - which PP doesn't do. Another advantage, as stated in the original post, is that if you move from a somewhat narrow layout template to a wider one there's no easy way (that I can see anyway) to "re-set" the display size of the images that have already been uploaded and scaled using the resize addon. |
|
#4
|
|||
|
|||
|
So... your hack does not produce sharper images, just fixes a maximum on the dimensions right?
__________________
http://se.nsuo.us - A photoblog of sensual, abstract nudes [may not be work safe for some] My Pixelpost Addons, Cheesecake-Photoblog Software |
|
#5
|
|||
|
|||
|
Quote:
|
|
#6
|
|||
|
|||
|
I am lost here - how does your hack produce sharper image? resizing using HTML? What about the horrible ragged edges that causes?
Or may be like you say increased sharpness is subjective.... I guess time to hack something which uses ImageMagicK - I am not happy with GD resizes either
__________________
http://se.nsuo.us - A photoblog of sensual, abstract nudes [may not be work safe for some] My Pixelpost Addons, Cheesecake-Photoblog Software |
|
#7
|
|||
|
|||
|
I think this does not quite work for me: I set the img width="480" height="320" then uploaded a photo in vertical orientation: 427x640 (WxH).
The imaged was resized to the right size, but the wrong way: it compressed the height - the 640 of the vertically oriented photo- to 320, and stretched the width - the 427 - to 480, so the image looks distorted. What I wanted is the image to keep its vertical orientation and only the proportions to be reduced accordingly. An yideas what might be wrong here? I set in index.php $max_width = 480; $max_height = 480; and also $max_width = 480; $max_height = 320; and it I got the same distorted image. It seems that it does not detect properly that the image is in vertical orientation because the width and height parameters in the template can only say that the image is width=480 and height 320, unless there is a way to assign the right size for vertical images. |
|
#8
|
|||
|
|||
|
Am not really sure if this is a valid hack at all.... might have worked for the original author but will be unacceptable to most
__________________
http://se.nsuo.us - A photoblog of sensual, abstract nudes [may not be work safe for some] My Pixelpost Addons, Cheesecake-Photoblog Software |
|
#9
|
|||
|
|||
|
There is not much feedback on it either. Anyway, is there a plugn or hack that allows me to properly resize images? In other words, if I have a landscape image of 1024x768 I want it resized to 480x320; if the image is vertical (768x1024), then I want it to be resized proportionally to 320x480, or better yet, constrain both sides but keep the original proportion: e.g. max height=320 and max width = 480. This would allow to display images with different sizes and orientations in a page that does not scroll if I chose the right dimensions.
|
|
#10
|
|||
|
|||
|
Ok, I downloaded the latest version of admin_autoresize and it works as expected; it properly resizes images in either orientation and keeps the proportions.
|
| Post Reply |
| Thread Tools | |
|
|