Need help with image Resizing

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
wizzard81
Forum Commoner
Posts: 66
Joined: Wed Jan 15, 2003 6:05 am
Location: Belgium
Contact:

Need help with image Resizing

Post by wizzard81 »

Hello,

I have installed the GD library on my apache webserver but need some help with resizing images that will be showed on the main page of my website.

Well if images will be like 640x480 i wan to resize them like this 150x200 so i set always the height of the image on 200 but i want if the image is largen then 150 pixels to cut out till the image is 150x200. So first i will set the height to 200.

Can someone helps me or knows a good tutorial about this?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it's simple math to figure it out... original_width / original_height * new_height = new_width.
wizzard81
Forum Commoner
Posts: 66
Joined: Wed Jan 15, 2003 6:05 am
Location: Belgium
Contact:

Post by wizzard81 »

But do you know the function of GD. Because my problem is i will have more then 1000 images. So i want to resize my image and cut out the part thats bigger.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Similar code here :
viewtopic.php?t=25346
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

have you even tried reading the [php_man]gd[/php_man] function list page? There are 2 right in a row that say resize in there description. :?
wizzard81
Forum Commoner
Posts: 66
Joined: Wed Jan 15, 2003 6:05 am
Location: Belgium
Contact:

Post by wizzard81 »

Yes i did but let me explain what i want first if the image is like 640x480 i want to resize to a height of 200px then the width is 267px then i want to crop out 67 pixels of the width. Is something like this possible?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

yes... you just copy a region of the scaled down image..
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

wizard81: willem? of jeroen? :P



btw, phpthumb.sourceforge.net does everything you want.
wizzard81
Forum Commoner
Posts: 66
Joined: Wed Jan 15, 2003 6:05 am
Location: Belgium
Contact:

Post by wizzard81 »

Timvw no i'm Kris :)

Thanks feyd for the help.
wizzard81
Forum Commoner
Posts: 66
Joined: Wed Jan 15, 2003 6:05 am
Location: Belgium
Contact:

Post by wizzard81 »

I still have a little question of you set the height on 200 doesn't the functions sets automatic the width. Like if you set the height of an image of 640x480 to 200 then the width should be 267px.

Because after this i can crop the 67pix out of it. Is something maybe possible? The best thing would be for me if have an image that i can get the height on 200 width on 200pix in a variable so that the real image not will be changed but it's only necessary to show the latest images in a gallery and on the main of my site.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the width in determined by you.. it doesn't automatically know you want to scale in 1:1.. maybe you want 1:3 scaling...
Post Reply