andy's php projects
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Script and site usage:
All of the scripts on this site are provided free for non-commerical, personal or non-profit use. If you find these scripts useful to you, appreciate the free support, or are just an all round nice person, then why not donate a little dosh? If you wish to use any of these in a commercial system, please refer to the payment plan.


Resize to a set width and crop to a set height

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    php.amnuts.com Forum Index -> Crop Canvas
View previous topic :: View next topic  
Author Message
ademaskoo
Newbie


Joined: 04 Jul 2004
Posts: 2
Location: Simi Valley, CA

PostPosted: Sun Jul 04, 2004 6:19 pm    Post subject: Resize to a set width and crop to a set height Reply with quote

I'm a n00b at php and haven't seriously used any pre-made scripts before - so bear with me.

What I'm trying to do seems simple. My website, www.simibargain.com, has realtors upload images of homes and then stores the original file into a folder and the name of the file in a database. I then want to call a script to return the thumbnail version of the image. For example: <img src="cropcanvas.php?file=house1.jpg">

The thumbnails' width should be resized to 200px (the height is unknown) and then center-cropped to 100px high.

I have no idea how to do this with andy's script or even where I should start. Any help would be VERY appreciated!!
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Bonzo
Newbie


Joined: 05 Jul 2004
Posts: 4

PostPosted: Tue Jul 06, 2004 2:22 pm    Post subject: Reply with quote

You could do that with a bit of php and include it all in one upload script; I was trying something like this before.

Look at ImageMagick as that seemed the best to me; below is some code for GD & IM I did this a while ago and the memory is going. Replace the variables to try out.

Anthony

GD
$thumb = ImageCreateTrueColor($new_width,$new_height);
ImageCopyResampled($thumb, $src_img, 0,0,0,0,($new_width-1),($new_height-1),$size[0],$size[1]);
ImageJPEG($thumb,$new_name);

IM
$ok0 = shell_exec($path_imagemagick."convert -size $normal_size $path_picture -geometry $normal_size $path_norm");
Back to top
View user's profile Send private message Visit poster's website
ademaskoo
Newbie


Joined: 04 Jul 2004
Posts: 2
Location: Simi Valley, CA

PostPosted: Tue Jul 06, 2004 10:01 pm    Post subject: Reply with quote

I got it working with GD. Thanks! Here's my code for anyone interested:

PHP:
<?php
      
// <img src="resizeimg.php?z=0&filename=image.jpg&width=200&height=100" width="200" height="100" border="1">
      
      
header("Content-Type: image/jpeg"); // Set the MIME type to image/jpeg
      
$path "upload/".$_GET['filename']; // Set the image path
      
$srcImg imagecreatefromjpeg($path);  // Create a Canvas for the source image and store it in memory
      
$srcSize getimagesize($path);  // Get the source image size and store the width and height in an array
      
$dstImg ImageCreateTrueColor($_GET['width'],$_GET['height']); // Create the Thumbnail Canvas
      
ImageCopyResampled($dstImg$srcImg0000,$_GET['width'],$_GET['height'],$srcSize[0], $srcSize[1]);  // Resize the Image and Save on the Canvas located in memory
      
imagejpeg($dstImg);  // output the raw image data stream
      
imagedestroy($scrImg);  // Free memory
      
imagedestroy($dstImg); // Free memory
?>


Simply access it by calling the page as if it were an image.

<img src="resizeimg.php?z=0&filename=image.jpg&width=200&height=100" width="200" height="100" border="1">
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Wed Jul 07, 2004 8:45 am    Post subject: Reply with quote

Hi and welcome to the board, both of you!

Sorry I didn't get to reply to this before now, but my computer has been out of action for a while.

Crop Canvas was the wrong class for thumbnailing. It crops an image - deletes portions of the overal size, but doesn't shrink or expand the actual image - just removes data from it. The Drop Shadow class was the one you should have looked at... It will resize images by pixel amounts, percentage amounts, from a size, to a size, and more.

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    php.amnuts.com Forum Index -> Crop Canvas All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group