photo resize question

so this is not it?

function resize_image($source, $dest, $max_width=60, $max_height=60) {
$source_quality = 80;

$src_img = ImageCreateFromJpeg($source);

$orig_x = ImageSX($src_img); 
$orig_y = ImageSY($src_img); 
$new_y = $max_height; 
$new_x = $orig_x / ($orig_y / $max_height);
if ($new_x > $max_width) { 
	$new_x = $max_width; 
	$new_y = $orig_y / ($orig_x / $max_width); 
} 

$dst_img = ImageCreateTrueColor($new_x,$new_y); 
ImageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $new_x, $new_y, $orig_x, $orig_y); 

$result = ImageJpeg($dst_img, $dest, $source_quality);
ImageDestroy($src_img); 
ImageDestroy($dst_img); 
return $result;

}

function resize_and_crop($source_file, $dest_file, $dest_side = 149) {
// Resize and crop an image to a square image that is filled with
// the source image.
require_once ‘Image/Transform.php’;
$im = Image_Transform::factory(‘GD’);
$im->load($source_file);

if ($im->getImageWidth() > $im->getImageHeight()) {
	// L'image d'origine est horizontale.
	$im->scaleByY($dest_side ); // scale proportionally the image so the height = 190.
	$im->crop($dest_side , $dest_side , ($im->new_x - $dest_side ) / 2, 0);
} else {
	// L'image d'origine est verticale.
	$im->scaleByX($dest_side ); // scale proportionally the image so the width = 190.
	$im->crop($dest_side , $dest_side , 0, ($im->new_y - $dest_side ) / 2);
}
$im->save($dest_file);
$im->free();
return true;

}

JG, YES! That is the image resizing code. I can assist you in changing the thumbnails in any way you wish.
Please tell me exactly what you would like to do different from the code that is now in place.

So, like, do you want all of the thumbnails a certain width, but to have them in correct proportion? That is fairly easy to do. Just have to get the current proportion and resize to fit it…

Let us know…

Each artists has a different page, right? That means each artists paintings are going to be different sizes, right?

So for each individual, we would like to have the thumbs proportionately sized based on their their biggest image.
So if there’s one artist that has a photo that’s landscape at 380 x 291, the thumb would automatically be reduced to something like 35%, which would scale the image down, and providing a thumb of something like 133 x 102.
does this make sense? right now, the way its set up, every thumb is a square of 120 x 120.

Well, yes, that can be done easily. One small issue… You really can’t know what the one artist has for sizes of his/her photos. You would have to scan all of their photos and then resize all of the thumbs to be the 35% of the largest size. And, what if they sent in a huge 1500x3000 pix… Hmmmm…

So, I think the best way is to do this. (Just my opinion, let me know what you think…)

Take the photo, resize the width only, to a set size. Let’s say 120 pixels wide.
Resize the picture to that width keeping the rest proportionate in size.
If the picture is portrait, this way would make the height longer than 120. This should be okay as it won’t matter if the page is a little longer.
If the picture is landscape, it will be resized to 120 pixels wide and the height would be shorter than 120 which is again okay for display.
Then, in your displayed html page, you only set the width of the images displayed to 120 and let the height take care of itself.

Of course, 120 is my choice during our discussions. You can set it to whatever you wish.

So, in the code you posted, this function:
function resize_image($source, $dest, $max_width=60, $max_height=60)
Will resize a picture to a format of 60x60 pixels.

And, this function:
function resize_and_crop($source_file, $dest_file, $dest_side = 149)
Uses a “PEAR” image library. It appears to be scaling and croping the file down to 149 pixels.
I am not sure of this without looking at and learning the “PEAR” code in the library “Image/Transform.php”.
(Do not post that code, it is available online alreay!) But, this could be done with just PHP instead of using
that library.

I guess the next question is do you want to change their code or create a new routine for thumbnails.
That depends on where we head from here… (Oh, and what width you want the thumbnails!)

Ernie, just to clarify-the artists photos can be found here:
http://harmonyhall.com/Gallery/artists.php

Ernie, i was giving the Transformphp file i quick scan, and noticed several places where it reads

[size=8pt]
(line 301) /**
* Scales the image to the specified height.
*
* This method preserves the aspect ratio

(line 321) * Scales an image by a percentage, factor or a given length
*
* This method preserves the aspect ratio[/size]

Is this not what we need? I am in now way experienced enough to even know how to read this code, so forgive me if this doesnt even apply.

Okay, I got it figured out for you… Sorry for the delay… The smallest thumbnails are 120x120.
This code will resize just those for you to 120x??? 120 wide with proportionate height. Hopefully this is what you are looking for. Sorry for the long delay for a simple fix. I have been dealing with a sick mother and been a little crazy lately. I should have figured this out must sooner… Hope it helps…

In the works.php , change this section:
if (!resize_and_crop($f, “uploads/works/$id/square_thumb_120_$unique_name”, 120)) {
die('Impossible to save cropped thumbnail for '.$f);
}
To this: (So we can use different code just for this thumbnail…)
[php]
if (!resize_thumb120($f, “uploads/works/$id/square_thumb_120_$unique_name”, 120)) {
die('Impossible to save cropped thumbnail for '.$f);
}
[/php]
Then, where you have the function resize_and_crop(), add this function:
[php]
function resize_thumb120($source_file, $dest_file, $dest_side = 120) {
// Resize and crop an image to a thumbnail image that is 120 pixels wide.
require_once ‘Image/Transform.php’;
$im = Image_Transform::factory(‘GD’);
$im->load($source_file);

// L’image d’origine est verticale.
$im->scaleByX($dest_side ); // scale proportionally the image so the width = 120.
$im->save($dest_file);
$im->free();
return true;
}
[/php]
You could just rewrite the current function to check for width of 120 and then alter the way it works.
But, I think a new function was better way as it is streamlined just for the one task. Hope that helps!

Hi Ernie, thanks for the reply.
So does this resize each and every thumbnail on each artists page? i just want to try and understand what were doing.

also, you said “Then, where you have the function resize_and_crop(), add this function:”
can you please specify where EXACTLY that code is? I really need to make sure i paste in the proper place.
thank you!

Well, first, you basically have three (3) different sizes of graphics…

The first is the actual photo. This is one size which doesn’t matter in our discussion.
I am assuming the code you posted resizes the picture to two other sizes, one 149 pixels and one 120 pixels.

These are handled in the functions we discussed. Then, they are displayed in your pages that you posted.

At least, that is what I see in your code. I would guess that this is done when the artist uploads the pictures.
Therefore, it will NOT alter the pictures already resized. You would have to create a routine to read the pictures,
check for their size, orientation and then resize each one. To do that, you would have to set up a loop to read thru your image directory resizing each image as needed… Is that what you want to do?

i dont know what to do anymore…lol…
Even if i resized the images that are there, im sure id have to recode php somewhere to not have it override whatever i do…

If there was a way to do it for new artists that are added, that would be great. But does that mean there are several php pages that need altering? The upload process all goes through adminphp, so the new artist uploads to the site would be called by the existing php…??

Well, if you add that new function I created for you and change that one line that calls it, I think that is all you need to do so far as the “new artists” loading pictures.

As far as the old ones, it depends on how it is stored online. I see where it takes the full picture and adds a name to it to tell it is a thumbnail_120 or thumbnail_149… So, the 120 bit would be easy to find. But, they are already saved small with errors. So, to fix all the old ones, you would have to look for the originals, then resize them and write over the old ones… Not too hard to do, but, a lot of work to get the folders and filenames sorted out…

ok…will look into it tomorrow.
Thank you again for all of your help.
:slight_smile:
Hopefully I will report back with some exciting code findings, or not…haha

Sponsor our Newsletter | Privacy Policy | Terms of Service