views:

35

answers:

1

How can I validate image properties(heigth, width) in Kohana 3 before resize? Or how can I use image resizing only if my image do not less size what I need?

What I want to do: during avatar uploading I must resize image if it bigger that i want. Or take action to prohibit uploading bigger avatar.

Now I have this rules:

public function avatar_validate($files)
{
    return Validate::factory($files)
        ->rules('avatar', array(
            'Upload::valid' => NULL,
            'Upload::type' => array(array('jpg','png','gif','bmp','gif')),
            'Upload::size' => array('3M')
                                )
                                );
}
A: 

After validation (type, filesize, etc) load an image in your controller with Image module.

$image = new Image($file['tmp_name']);
if ($image->width > 800 OR $image->height > 600)
{
    $image->resize(800, 600, null);
    $image->save('path/'.$file['name']);
}
else
{
    move_uploaded_file($file['tmp_name'], 'path/'.$file['name']);
}
atma