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.


Image resize and fit to dimensions

 
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
max0matic
Newbie


Joined: 26 Feb 2004
Posts: 5

PostPosted: Mon Apr 26, 2004 11:27 am    Post subject: Image resize and fit to dimensions Reply with quote

I want to pass a given width and height and the script should extract the biggest possible chunk of picture and rescale it to the size wanted retaining aspect ration..

lets say I want a 300x100 picture and I pass a 600x400 picture
the script takes 600x200 and resamples it in size to 300x100.

Is this possible.. I was trying around but.. hmm...
didn't get it working.
Back to top
View user's profile Send private message
drumdance
Newbie


Joined: 08 May 2004
Posts: 1
Location: Boulder, CO, USA

PostPosted: Sat May 08, 2004 1:53 pm    Post subject: Resizing Reply with quote

max0matic, I hacked around with the Javascript and found a way that does most of what you want. (I need the same thing)

It requires a fair amount of changes to the script, but the basic approach is to capture $this->img['sizes'][0] and $this->img['sizes'][1] to separate vars and, if they are bigger than whatever size you need, reset the separate vars to the correct size using the percentage diff:

Code:

//in class.cropinterface::load_Javascript, somwehere before the <script> tag output

//capture img sizes to separate vars
$this->size0=$this->img['sizes'][0];
$this->size1=$this->img['sizes'][1];

//keep the picture no more than 600px wide
//you'' probably want to use a class var for this instead of an absolute

if($this->size0>600) {
   $this->size0=600
   $diff=$this->img['sizes'][0]- $this->size0;
   $this->percentage=1-($diff)/$this->img['sizes'][0];
   //scale new height to the same as new width
   $this->size1=round($this->size1*$this->percentage)
}/

You'll have to look for places where this->img['sizes'] is used in output display (but not file management i.e. cropping) and replace them with $this->size0 and $this->size1 where appropriate.

Next, you have to change the Javascript output in my_submit():

Change this:
Code:

self.location.href = '{$action}'+ '&sx=' +
         (dd.elements.theCrop.x - dd.elements.theImage.x) + '&sy=' +
         (dd.elements.theCrop.y - dd.elements.theImage.y) + '&ex=' +
         ((dd.elements.theCrop.x - dd.elements.theImage.x) + dd.elements.theCrop.w) + '&ey=' +
         ((dd.elements.theCrop.y - dd.elements.theImage.y) + dd.elements.theCrop.h);


To this:

Code:

sx=(dd.elements.theCrop.x-dd.elements.theImage.x)*(1/$this->percentage);
sx=Math.round(sx);

sy=(dd.elements.theCrop.y-dd.elements.theImage.y)*(1/$this->percentage);
sy=Math.round(sy);

ex=(dd.elements.theCrop.x-dd.elements.theImage.x + dd.elements.theCrop.w)*(1/$this->percentage)
ex=Math.round(ex);

ey=(dd.elements.theCrop.y-dd.elements.theImage.y + dd.elements.theCrop.h)*(1/$this->percentage)
ey=Math.round(ey);

self.location.href = '{$action}'+ '&sx=' + sx + '&sy=' + sy + '&ex=' + ex + '&ey=' + ey;


(You can compress that into fewer lines of code, but it's easier to unserstand this way.)

This does not actually resize the image file, just the display. I have a separate class to do that, so I didn't try to solve that problem.

Good luck!
Back to top
View user's profile Send private message Send e-mail
max0matic
Newbie


Joined: 26 Feb 2004
Posts: 5

PostPosted: Sat May 08, 2004 6:16 pm    Post subject: Thank you but I solved it.... Reply with quote

Thank you but I solved it...
Check out http://flashrocket.worldoptimizer.com/
Back to top
View user's profile Send private message
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