Algebra!  I aced that in 7th grade!  (don't ask me about all the other
years of math. Haha.. I think I just got bored and slept a lot or
something)

-TG

> -----Original Message-----
> From: Jonel Rienton [mailto:[EMAIL PROTECTED] 
> Sent: Friday, October 15, 2004 11:02 AM
> To: Gryffyn, Trevor
> Cc: php php; Mag
> Subject: Re: [PHP] Advanced maths help (for GD image functionality)
> 
> 
> it's algebra at work :)
> 
> nicely done.
> 
> 
> On Oct 15, 2004, at 8:57 AM, Gryffyn, Trevor wrote:
> 
> > Good questions.. Here's some stuff to play with:
> >
> >> Heres my maths problems in 2 parts:
> >>
> >> Problem 1)
> >> I need to scale down an image (eg: example.jpg) to
> >> height of 120 pixels while maintaining the images
> >> proportions.
> >>
> >> eg:
> >> if i have an image of (height and width) 800x600 what
> >> would the dimensions be if the height was 120?
> >
> > Proportions can be figured out by doing cross multiplication.  Say
> > you're trying to figure out percentages, do something like this:
> >
> >   x           75
> > -----    x  -------
> > 100           185
> >
> >
> > Multiple cross ways and you get:
> >
> > 185x = 7500
> >
> > Divide both sides by 185 to get just an "x = " and you get 
> 40.54.   75
> > is 40.54% of 185.
> >
> >
> > You can use this to get your proportions for images too.  It doesn't
> > have to be 100 at the bottom of that one side.  Say you 
> have an image
> > that's 1275 x 852 and you want to create a 120 x ???? Thumbnail.
> >
> >
> > 1275 w             120 w
> > ------       x     -------
> > 852  h               x h
> >
> >
> >
> > 1275x = 102240     (1275 times x = 120 times 852)
> >
> > Divide both sides by 1275 and you get:
> >
> > X = 80.19....  Which you might round to 80.
> >
> >
> > So a 1275 x 852 image scale down to 120 x 80.
> >
> > Easy, right? :)
> >
> >
> >> Problem 2)
> >> After getting the above image now I need the x and y
> >> parameters to cut a h120 x w90 thumb *from the center
> >> of the image*
> >>
> >> eg: if from problem 1 the result is an image of 120 x
> >> 160 then x=35 and y=125 (I think, i told you i suck at
> >> maths.. :-D )
> >
> >
> > This one's even easier.  Using the same 1275 x 852 image:
> >
> >
> > 1275 w - 120 w = 1155 (difference in widths)
> >
> > 1155 / 2 = 577.5 (578 rounded let's say).  That's how much 
> space you'll
> > have on either wide width-wise.  That'll give you a 120w 
> "center cut"
> >
> > Do the same with the height:
> >
> > 852 - 90 = 762
> >
> > 762 / 2 = 381
> >
> >
> > So your top-left pixel to start cutting would be at 578 x 381.
> >
> >
> > Try it out and let us know how it worked.
> >
> > -TG
> >
> > -- 
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> 
> 

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to