Thank you for your help Malasho. That didnt seem to work.
Here is the code including the $this object.
/**
* Rotates the scratch by given degrees. No cropping will occurr - the canvas will be resized to fit the new boundaries of the image if necessary.
*
* @param float $degrees Angle in degrees to rotate the image. Positive angles indicate a clockwise rotation, negative values are counter-clockwise.
* @param mixed $background Specifies the color of the uncovered zone after the rotation
*/
public function rotateScratch($degrees, $background = 0)
{
$this->_scratchResource = imagerotate($this->_scratchResource, $degrees, $background);
$this->_width = imagesx($this->getScratchResource());
$this->_height = imagesy($this->getScratchResource());
}
public function isScratchTrueColor()
{
return imageistruecolor($this->getScratchResource());
}
/**
* Applies sharpening to the current scratch
*
* @return bool Returns TRUE on success or FALSE on failure
*/
public function sharpenScratch()
{
// this needs a $strength parameter but I don't know how matrix convultions work
$matrix = array(
array(-1, -1, -1),
array(-1, 16, -1),
array(-1, -1, -1)
);
$divisor = 8;
$offset = 0;
return imageconvolution($this->getScratchResource(), $matrix, $divisor, $offset);
}
/**
* Create a blank true-colour image resource with alpha settings enabled
*
* @param int $width
* @param int $height
* @return resource
*/
protected function _getBlankImageResource($width, $height)
{
$resource = imagecreatetruecolor($width, $height);
imagealphablending($resource, false);
imagesavealpha($resource, true);
return $resource;
}
/**
* Resample the scratch to a specific width and height -- will stretch the image, ignoring aspect ratios. To keep aspect ratios intact, use other functions like resampleScratchLongEdge and resampleScratchToMaximumDimensions
*
* @param mixed $width
* @param mixed $height
*/
public function resampleScratch($width, $height) {
if ($this->isScratchTrueColor()) {
$temp = $this->_getBlankImageResource($width, $height);
} else {
// determine fill background, transparent if possible
$fill = imagecolortransparent($this->getScratchResource());
if ($fill === -1) {
// no transparency found, find the closest colour to white in the palette and use that as the background
$fill = imagecolorclosest($this->getScratchResource(), 255, 255, 255);
}
$temp = imagecreate($width, $height);
imagepalettecopy($temp, $this->getScratchResource());
imagecolortransparent($temp, imagecolortransparent($this->getScratchResource())); // set transparency of new image to same as old image
imagefill($temp, 0, 0, $fill);
}
/** // Fixed Size Thumbnails - ****
if ($this->_width > 835 || $this->_height > 1280) {
imagecopyresampled($temp, $this->getScratchResource(), 0, 0, 0, 0, $width, $height, $this->_width, $this->_height);
} else {
$source = getimagesize($this->getFilePath());
$srcX = $width;
$srcY = $height;
if (($source[0]*$srcY) > ($source[1]*$srcX)) {
$srcX = ($height / $source[1]) * $source[0];
$offsetX = ($width - $srcX) / 2;
} else {
$srcY = ($width / $source[0]) * $source[1];
$offsetY = ($height - $srcY) / 2; ;
}
imagecopyresampled($temp, $this->getScratchResource(), $offsetX, $offsetY, 0, 0, $srcX, $srcY, $this->_width, $this->_height);
}
// End Fixed Size Thumbnails code ****
*/
// imagecopyresampled($temp, $this->getScratchResource(), 0, 0, 0, 0, $width, $height, $this->_width, $this->_height);
$this->_scratchResource = $temp;
$this->_width = $width;
$this->_height = $height;
}
/**
* Returns a GD image resource for the current scratch
*
*/
public function getScratchResource()
{
return $this->_scratchResource;
}
/**
* Overlay another GD resource onto the current scratch at the given offset
*
* @param ISC_IMAGE_LIBRARY_GD $image
* @param mixed $offsetX
* @param mixed $offsetY
*/
public function overlayImage(ISC_IMAGE_LIBRARY_GD $image, $offsetX, $offsetY)
{
// when watermarking is implemented this may need to be re-examined for when gifs or 8bit pngs are used
$overlayResource = $image->getScratchResource();
$overlayWidth = $image->getWidth();
$overlayHeight = $image->getHeight();
if ($offsetX < 0) {
$offsetX = $this->getWidth() + $offsetX - $overlayWidth;
}
if ($offsetY < 0) {
$offsetY = $this->getHeight() + $offsetY - $overlayHeight;
}
imagecopyresampled($this->getScratchResource(), $overlayResource, $offsetX, $offsetY, 0, 0, $overlayWidth, $overlayHeight, $overlayWidth, $overlayHeight);
}
}