How to crop images (long height images and long width images

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
eshban
Forum Contributor
Posts: 184
Joined: Mon Sep 05, 2005 1:38 am

How to crop images (long height images and long width images

Post by eshban »

Hello,

I am working on a shopping cart, and i am facing a severe problem.
I have two types of images to display at "PRoducts PAGE".
i.e.

1) Images that have long width but short height ( example= 500x275)
2) Images that have long height but short width. (example =200 x 400 )

I add products with images in shopping cart from admin panel of webiste. but when i see the images in client side it wont looks good , because some images have long height and some have long width, so i am unable to adjust the images properly.

I want to automate this process when whatever image i can add from admin section , whether it has long height or whether it has long width, my code will automatically crop it, and adjust it, so that images displayed in client section have equal height and width.

currently in my products page if i add one image which has long width and secondly i add image with long height then it disturbs the layout.

so please please suggest me that what can i do to solve this problem

thanks in advance
Paw
Forum Newbie
Posts: 20
Joined: Tue Jul 17, 2007 10:27 am

Post by Paw »

If available on your target server, you may want to look into http://www.php.net/gd -- more specifically http://www.php.net/manual/en/function.imagecopy.php
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

imagecopyresampled() may be of interest as well. If you want to, you can also come up with a simple procedure that takes a width : height ratio that you specify to fit all of your images in, then compares the width : height ratio if the image being manipulated, and depending on the ratio (if image ratio is bigger than the set ratio, then the width is too large, if image ratio is smaller, then the height is too large) and the actual values, you can determine whether to resize it, and which property controls the shrinking ratio. ... It's a bit simpler than it sounds.
Post Reply