Pixelpost

Authentic Photoblog Flavour


Go Back   Pixelpost Forum > DEVELOPMENT > Hacks and Modifications

Post Reply
 
Thread Tools
  #1  
Old 03-15-2006, 03:14 AM
moment17 Offline
forum loafer
 
Join Date: Mar 2006
Posts: 3
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;    

}
and in index.php down about line 253 (just below $image_width = $image_extra['0']; and $image_height = $image_extra['1'];) add:

Code:
$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:
Code:
$tpl = str_replace("<IMAGE_WIDTH>",$image_width,$tpl);
$tpl = str_replace("<IMAGE_HEIGHT>",$image_height,$tpl);
to:
Code:
$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.
Reply With Quote
  #2  
Old 03-15-2006, 03:23 AM
se.nsuo.us Offline
pixelpost guru
 
Join Date: Dec 2005
Location: Somewhere in India
Posts: 624
Quote:
Originally Posted by moment17
I wasn't happy with the quality of admin_resize even at 100%
What do you mean by this? what was the problem that your hack solves?
__________________
http://se.nsuo.us - A photoblog of sensual, abstract nudes [may not be work safe for some]
My Pixelpost Addons, Cheesecake-Photoblog Software
Reply With Quote
  #3  
Old 03-15-2006, 05:07 AM
moment17 Offline
forum loafer
 
Join Date: Mar 2006
Posts: 3
Quote:
Originally Posted by se.nsuo.us
What do you mean by this? what was the problem that your hack solves?
The image quality that the resize addon produces in the scaled images isn't what I had hoped. I haven't looked at the code of it, but I assume it uses GD. Granted jpg to jpg is a lossy process, but I honestly have never found the GD libs to produce a very high quality product, tending to excessively blur images. (I'm using php 4.4.0 linked against gd 2.0.33, so it's not an "old libs" issue.)

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.
Reply With Quote
  #4  
Old 03-15-2006, 05:14 AM
se.nsuo.us Offline
pixelpost guru
 
Join Date: Dec 2005
Location: Somewhere in India
Posts: 624
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
Reply With Quote
  #5  
Old 03-15-2006, 05:59 AM
moment17 Offline
forum loafer
 
Join Date: Mar 2006
Posts: 3
Quote:
Originally Posted by se.nsuo.us
So... your hack does not produce sharper images, just fixes a maximum on the dimensions right?
Both. Sharpness is somewhat subjective, but I don't think the quality is there with the scaled images produced by the addon. I've been using GD for over six years and it's always been less than spectacular in my opinion. (I've been in graphics for 20 years and spend probably too much time looking at images and their relative quality).
Reply With Quote
  #6  
Old 03-15-2006, 06:21 AM
se.nsuo.us Offline
pixelpost guru
 
Join Date: Dec 2005
Location: Somewhere in India
Posts: 624
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
Reply With Quote
  #7  
Old 07-13-2006, 04:04 AM
romamor Offline
pp regular
 
Join Date: Feb 2005
Posts: 21
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.
Reply With Quote
  #8  
Old 07-13-2006, 04:48 AM
se.nsuo.us Offline
pixelpost guru
 
Join Date: Dec 2005
Location: Somewhere in India
Posts: 624
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
Reply With Quote
  #9  
Old 07-13-2006, 12:15 PM
romamor Offline
pp regular
 
Join Date: Feb 2005
Posts: 21
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.
Reply With Quote
  #10  
Old 07-13-2006, 01:15 PM
romamor Offline
pp regular
 
Join Date: Feb 2005
Posts: 21
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.
Reply With Quote
Post Reply


Thread Tools




All times are GMT. The time now is 01:50 AM.

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd. | Style Design: d3 designs