tags:

views:

9

answers:

0

Okay, I'm over my head and fumbling in the dark here. I'm trying to modify a class to crop an image by setting the height, width and starting x & y positions. The class I'm using handles everything but the starting x & y, and try as I might all I can do is blow it up.

Can someone help me with this??

the relevant function is listed below. I tried adding new variables and then changing the imagecopyresampled bit, but it just returns the image squished into place rather than cropped properly.

Thanks in advance!!

public function resizeImage($newWidth, $newHeight, $option="auto")
            {
                // *** Get optimal width and height - based on $option
                $optionArray = $this->getDimensions($newWidth, $newHeight, $option);

                $optimalWidth  = $optionArray['optimalWidth'];
                $optimalHeight = $optionArray['optimalHeight'];


                // *** Resample - create image canvas of x, y size
                $this->imageResized = imagecreatetruecolor($optimalWidth, $optimalHeight);
                imagecopyresampled($this->imageResized, $this->image, 0, 0, 0, 0, $optimalWidth, $optimalHeight, $this->width, $this->height);


                // *** if option is 'crop', then crop too
                if ($option == 'crop') {
                    $this->crop($optimalWidth, $optimalHeight, $newWidth, $newHeight);
                }
            }