I have a thumbnail upload and crop script that uses JImage.
It normally works fine, but I have an install on a shared hosting, so I am using the Joomla ftp layer to combat file permissions problems.
However, I am getting the following error when trying to save to file
'Unable to open xxx/xxxx/xxx.jpg for writing, Permission denied'.
The final processed image file is not saved.
Here is my code:
$thumb = new JImage($uploadPath);
$sourceWidth= $thumb->getWidth();
$sourceHeight = $thumb->getHeight();
$targetWidth = $width;
$targetHeight = $height;
$sourceRatio = $sourceWidth / $sourceHeight;
$targetRatio = $targetWidth / $targetHeight;
if ( $sourceRatio < $targetRatio ) {
$scale = $sourceWidth / $targetWidth;
} else {
$scale = $sourceHeight / $targetHeight;
}
$resizeWidth = (int)($sourceWidth / $scale);
$resizeHeight = (int)($sourceHeight / $scale);
$cropLeft = (int)(($resizeWidth - $targetWidth) / 2);
$cropTop = (int)(($resizeHeight - $targetHeight) / 2);
$thumb=$thumb->resize($resizeWidth,$resizeHeight,true);
$thumb=$thumb->crop($width, $height,0,0,true);
$thumbpath = JPATH_SITE.DS.'images'.DS.'tours'.DS.'thumbnails'.DS.$id.'.jpg';
$thumb->toFile($thumbpath,'IMAGETYPE_JPG');
JFile::delete($uploadPath);
The image is uploading to my temp folder, and using $thumb->isLoaded() I know that there is an image loaded to the object, it is just the last toFile where it fails.