Forum Moderators: coopster

Message Too Old, No Replies

Thumb - height needs to be always 200

width max 200 (fluid)

         

henry0

11:12 am on Sep 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I can't find the correct way to acheive my goal
I resize an image and save it
up to there it does the job.

but I need the height to be always 200
the width does not matter but the max will be 200

this is what works but again I do not figure how change it to deliver that fixed height


$dest_x = $_POST['dest_x']; // echo"X $dest_x<br>";
$dest_y = $_POST['dest_y']; // echo"Y $dest_y";

//$dest_x = 200;
//$dest_y = 200;

if (imagesx($i) > $dest_x or imagesy($i) > $dest_y) {
//Is the width of the original bigger than the height?
if (imagesx($i) >= imagesy($i)) {
$thumb_x = $dest_x;
$thumb_y = imagesy($i)*($dest_x/imagesx($i));
} else {
$thumb_x = imagesx($i)*($dest_y/imagesy($i));
$thumb_y = $dest_y;
}
} else {

$thumb_x = imagesx($i);
$thumb_y = imagesy($i);
}

$thumb = imagecreatetruecolor($thumb_x,$thumb_y);

imagecopyresampled($thumb, $i ,0, 0, 0, 0, $thumb_x, $thumb_y, imagesx($i), imagesy($i));

imagejpeg($thumb, "img/thumbs/t_$filename", 90);

Marshall

11:21 am on Sep 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Not sure if this will help, but if you are using CSS, you can make it:

img {
height: 200px;
width: auto;
}

Of course, this would apply to all images, so you may want to do a class:

img.height {
height: 200px;
width: auto;
}

Since I am not familiar with PHP, this is where my suggestion stops :)

Marshall

henry0

11:48 am on Sep 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks, that works on client side but I rather have it done server side.
I have a solution that works too but I find it too procedural.
I made a script that creates an overlay
by using a white img 200 X 200
and overlaying the resized img on top of the whire one while making on the fly a transparency.
I can live with it but if have a thousand of requests then it will add too much load.

Marshall

12:10 pm on Sep 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Sorry I cannot be of more help, but I seem to recall that this issue came up within the past few months. You may want to search WebmasterWorld, though I do not think it was PHP related, but it did have to do with thumbnails.

Marshall

jatar_k

1:10 pm on Sep 17, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



so are you going to make it bigger if it is less than 200?

see what the present height is
decide what you need to do
get width to height ratio
use ratio on 200 to make the new width
create new image

henry0

1:34 pm on Sep 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Correct if less than 200 (height) I will make it bigger
I will try it your way
thanks

jatar_k

1:47 pm on Sep 17, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



just remember when you increase you lose quality, though 200 isn't that big

henry0

2:10 pm on Sep 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Funny you mention that :)
I was thinking about it too
and came to the conclusion that I shall not do it
but stick to my overlay idea (exposed above)
and instead of calling the script on the fly
I will first get the height, if <200 then do the overlay
and store the new image with the overlay addition
so I will save tons of php calls
<edit>
reason for doing it:
I need rows of same height without using client side
</edit>