GD

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
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

GD

Post by Jim_Bo »

Hi,

How can I alter the following code so I can resize the width making the heigh wild to keep the proportion?

Code: Select all

 
$Config_tbwidth_wide = 200;
$Config_tbheight_wide = 200;
 
$Config_tbwidth_tall = 200;
$Config_tbheight_tall = 200;
 

Thanks
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: GD

Post by requinix »

Here's an analogy of what you just did:
You just handed us a blank piece of paper and asked us how long ago the tree was cut down.

You have three options:
1. Post all the code that has to do with image resizing.
2. Explain what those variables mean.
3. Since you don't seem to understand PHP well, it's a good guess you didn't develop this yourself. Ask your question to the person who did, or tell us what library/code sample you downloaded.
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Re: GD

Post by Jim_Bo »

Wow.. they are simple variables defining the height and witdth to resize the images too... I was asuming a simple astrix used as a wild setting.

PS.. I like the way you assume I dont understand php well mate.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: GD

Post by onion2k »

Jim_Bo wrote:PS.. I like the way you assume I dont understand php well mate.
I thought it was quite a fair assumption given your question and further response.

You can't use a wildcard. You'll need to write some code to get the width and height of the image (using getimagesize()), then calculate the new size using a straightforward formula to maintain the aspect ratio.
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: GD

Post by McInfo »

Algebra lesson:

To find the new height after resizing the width, use this formula:

Code: Select all

$new_height = $new_width * $old_height / $old_width;
Suppose you have an image whose width is 320 pixels and height is 240 pixels. You want to resize the width to 100 pixels. The new height will be 75 pixels.
Equivalent-Ratios.png
Equivalent-Ratios.png (3.72 KiB) Viewed 204 times
Edit: This post was recovered from search engine cache.
Attachments
Equivalent-Ratios.png
Equivalent-Ratios.png (3.72 KiB) Viewed 251 times
Last edited by McInfo on Tue Jun 15, 2010 4:42 pm, edited 1 time in total.
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Re: GD

Post by Jim_Bo »

Hi,

I have it solved, I allready new the information posted, I guess my question was bit lame in the way I asked.. I just assumed given it was GD and posted width and height variable it would make sence as I new was I was trying to acheive.

Small issue I still have is checking whether the form file feilds contain a file or not .. If any of the fields hold a file then exicute the code.

I thouhght something like

Code: Select all

 
if ($_FILES['image']['size'] > 0) {
 
Would do it, but the code seems to exicute even when the feilds dont contain any files. How would this be done?

Thanks
Post Reply