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.


How to Crop and resize the cropped area?

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


Joined: 06 Feb 2004
Posts: 5

PostPosted: Fri Feb 06, 2004 9:54 am    Post subject: How to Crop and resize the cropped area? Reply with quote

Hi again, now I have a new question, how to use the class to resize the cropped area to a fixed width preserving the image aspect ratio?
Back to top
View user's profile Send private message
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Fri Feb 06, 2004 10:53 am    Post subject: Reply with quote

Just done a little experimenting with this and it's a fairly simple update. I'll produce a version of the class tonight and upload it with the changes in there, but if you're feeling adventurous then here are the instructions.

Add this function to the class

PHP:
<?php

function setCropSizeProportional($w$h 0)
{
    if (empty(
$this->_usePropCropSize)) {
        
$this->_usePropCropSize = array($w$h);
    } else {
        if (!
$this->_usePropCropSize[0]) {
            
$this->_usePropCropSize[0] = ($h $this->img['sizes'][1]) * $this->img['sizes'][0];
        } else {
            
$this->_usePropCropSize[1] = $this->img['sizes'][1] / ($this->img['sizes'][0] / $this->_usePropCropSize[0]);
        }
        
$this->setCropDefaultSize($this->_usePropCropSize[0], $this->_usePropCropSize[1]);
   }
}

?>


(obviously you won't need to include the '<?php / ?>' tags as I only put them in there for the colour coding).

Add this to the class variable list

var $_usePropCropSize;

Add this when initializing the variables in the 'cropInterface' function

$this->_usePropCropSize = array();

In the 'loadInterface' function you have some code that looks like:

PHP:
<?php

$this
->file $filename;
$this->img['sizes'] = getimagesize($filename);
if (!
$this->crop['width'] || !$this->crop['height'])
{
        
$this->setCropDefaultSize(($this->img['sizes'][0] / 5), ($this->img['sizes'][1] / 5));
}

?>


make it look like

PHP:
<?php

$this
->file $filename;
$this->img['sizes'] = getimagesize($filename);
if (!
$this->crop['width'] || !$this->crop['height'])
{
        if (!empty(
$this->_usePropCropSize)) {
                
$this->setCropSizeProportional(00);
        } else {
                
$this->setCropDefaultSize(($this->img['sizes'][0] / 5), ($this->img['sizes'][1] / 5));
        }
}

?>



And that's it. Now when you can to call the class you might do something like this:

PHP:
<?php

        
require_once 'class.cropinterface.php';
        
$ci = new cropInterface();
        
$ci->setCropSizeProportional(2000);

?>


By setting 'w' to a value and making 'h' 0 it will make the height proportional to the width based on the image. If you set 'w' to be 0 and 'h' to a value, then it will set the width proportional to the image.

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Mich
Newbie


Joined: 06 Feb 2004
Posts: 5

PostPosted: Fri Feb 06, 2004 11:56 am    Post subject: Reply with quote

I don?t know if I did something wrong (of course I?m an adventurer) or you didn?t understand what I was asking for (or maybe we get both in trouble), the only visible change I?m seeing is the cropping rectangle area size is now setted by setCropSizeProportional(w,h); which is great, at least for large images.

But the thing I?m asking is to assign a width (or height) max for cropped images, i.e. if I crop an image in 400*800px, resize it (without crop) to 200*400px. to finally store it. I did it but procesing the files twice, first crop and then resize, but I want to know if this can be done in only one pass.

I don?t know if you don?t understand me or not, perhaps I?m doing something wrong, or both are confused... Laughing

Thanks a lot for your 24/7 support, and tonight I?ll test the new version, sorry for the annoyances, and sorry one more time for my poor english who surely is the guilty of this mess.

PD: I'm thinking... maybe next weeks I'll try to ask for some features, Twisted Evil muahahahahaha!!
Back to top
View user's profile Send private message
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Fri Feb 06, 2004 12:05 pm    Post subject: Reply with quote

Mich wrote:
But the thing I?m asking is to assign a width (or height) max for cropped images, i.e. if I crop an image in 400*800px, resize it (without crop) to 200*400px. to finally store it. I did it but procesing the files twice, first crop and then resize, but I want to know if this can be done in only one pass.


Oh.. I see, you're wanting to actually resize the image after you've cropped it. Okay, well, this thread might help you out:

http://php.amnuts.com/forums/viewtopic.php?t=66

it extends the base crop-canvas class to enable image resizing as well as cropping.

Alternatively, you could use my thumbnail class (but it would still be a 2-step process like you use now).

I am thinking of builidng one big class that incorporates the cropping, resizing and masking classes, together with a few extra functions. If I did that, though, I'd probably ask money for it (though a nominal amount... $15 or less, probably)... But I'm not sure yet.

Mich wrote:
Thanks a lot for your 24/7 support, and tonight I?ll test the new version, sorry for the annoyances, and sorry once for my poor english whose the guilty of this mess.


No need to apologise for your english!! I can only speak the one language, so your english is infinetly better than my foreign language skills. Very Happy

Mich wrote:
I'm thinking... maybe next weeks I'll try to ask for some features


Always good to hear those kinds of requests! Smile

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
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