...

View Full Version : Changes to Element's thumbnail system.



thesavior
09-02-2006, 01:53 AM
Im looking at Elements snippit here: http://codingforums.com/showthread.php?t=72029

But there is something keeping me from using it again, Ive used in the past for something else. But what I want it to do is I want all my images to keep the same size ratio, so tall and thing pictures stay tall and thin, just get smaller. Last time I used it, it made everything exactly what I put for max height and max width.

vinyl-junkie
09-02-2006, 04:21 AM
Are you getting an error message or what when you try to run this script? Saying that "there is something keeping me from using it" isn't particularly helpful to us. What exactly is happening? Did you use that script as-is or did you make modifications to it? If the latter, show us your code.

thesavior
09-02-2006, 04:52 AM
no, like i said, the thing holding me back is:
But what I want it to do is I want all my images to keep the same size ratio, so tall and thing pictures stay tall and thin, just get smaller.

It works fine as it is, but it doesn't keep the size ratio of the image. That is what is holding me back. Sorry if I wasn't clear.

vinyl-junkie
09-02-2006, 06:12 AM
Thanks for the clarification.

Do you know what the dimensions are of one of the images you're trying to resize? If not, go into Windows Explorer and right click over the image to see the dimensions.

Next, what do you have $max_width and $max_height set as in your script? And to repeat an earlier question, did you change anything in the original script? If so, what?

Element
09-02-2006, 08:42 AM
It doesn't keep the size ratio? It does for me. Try this out. Ignore the error jpg stuff or remove it.




<?php

error_reporting(E_ALL);

// Input
$s_image = $_GET['image']; // Image url set in the URL. ex: thumbit.php?image=URL
$e_image = "error.jpg"; // If there is a problem using the file extension then load an error JPG.
$max_width = 60; // Max thumbnail width.
$max_height = 100; // Max thumbnail height.
$quality = 100; // Do not change this if you plan on using PNG images.

// Resizing and Output : Do not edit below this line unless you know what your doing.

if (preg_match("/.jpg/i", "$s_image")) {

header('Content-type: image/jpeg');
list($width, $height) = getimagesize($s_image);
$ratio = ($width > $height) ? $max_width/$width : $max_height/$height;
if($width > $max_width || $height > $max_height) {
$new_width = $width * $ratio;
$new_height = $height * $ratio;
} else {
$new_width = $width;
$new_height = $height;
}
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($s_image);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagejpeg($image_p, null, $quality);
imagedestroy($image_p);

} elseif (preg_match("/.png/i", "$s_image")) {

header('Content-type: image/png');
list($width, $height) = getimagesize($s_image);
$ratio = ($width > $height) ? $max_width/$width : $max_height/$height;
if($width > $max_width || $height > $max_height) {
$new_width = $width * $ratio;
$new_height = $height * $ratio;
} else {
$new_width = $width;
$new_height = $height;
}
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefrompng($s_image);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagepng($image_p, null, $quality);
imagedestroy($image_p);

} elseif (preg_match("/.gif/i", "$s_image")) {

header('Content-type: image/gif');
list($width, $height) = getimagesize($s_image);
$ratio = ($width > $height) ? $max_width/$width : $max_height/$height;
if($width > $max_width || $height > $max_height) {
$new_width = $width * $ratio;
$new_height = $height * $ratio;
} else {
$new_width = $width;
$new_height = $height;
}
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromgif($s_image);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagegif($image_p, null, $quality);
imagedestroy($image_p);

} else {


}

?>


I think that's a older version... but I'm using it right now it it seems to work just fine

http://chat.realmsrp.com/~dermetz/profile.php?U=Syn

The image upper right is thumbnailed with that same script.

litebearer
09-02-2006, 01:12 PM
If you need, here is another one to help.

http://www.nstoia.com/toh/technical/imageresize/index.php

Lite...

thesavior
09-02-2006, 06:16 PM
Ok, I will try it. I just remember the past version of this not keeping a size ratio.
Thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum