We help IT Professionals succeed at work.

add crop function to class simpleimages.php

denny3d
denny3d asked
on
Medium Priority
589 Views
Last Modified: 2012-05-12
Hi EE
I newbie to php
i used a simpleimage.php to upload and resize image ... but i need to crop some images.
How i add a crop function to this class?
Regards
Denis
SimpleImage.php
Comment
Watch Question

2015 Top Expert (Most Article Points)
CERTIFIED EXPERT
Commented:
Here is a crop function using imagecopyresized

http://uk.php.net/manual/en/function.imagecopyresized.php 
$dst_image = 'output.jpg';
$src_image = imagecreatefromjpeg('input.jpg');
$dst_x = 0;
$dst_y = 0;
$src_x = 0;
$src_y = 0;
$dst_w = 500;  //Adjust these numbers to suit your image
$dst_h = 500;
$src_w = 500;
$src_h = 500;

function crop($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
{
    
    $cut = imagecreatetruecolor($dst_w, $dst_h);
    
    imagecopyresized($cut, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
    imagejpeg($cut, $dst_image);
}


//Call function with arguments//
crop($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);

Open in new window

Explore More ContentExplore courses, solutions, and other research materials related to this topic.