function cropImage($imagePath, $width, $height) {
global $module;
$folderPath = $this->crop_folder;
$parent_path = str_replace("/images/crop","",$folderPath);
$parent_path = str_replace("\\images\\crop","",$parent_path);
if(!JFolder::exists($parent_path)){
if(mkdir($parent_path, 0777)){
} else {
echo "Error: Can't create folder for resize image!"; exit();
}
}
$parent_path = str_replace("/crop","",$folderPath);
$parent_path = str_replace("\\crop","",$parent_path);
if(!JFolder::exists($parent_path)){
//if(JFolder::create($folderPath)){echo "ok";} else {echo "not ok";}
if(mkdir($parent_path, 0777)){
if(mkdir($folderPath, 0777)){
} else {
echo "Error: Can't create folder for crop image!";
}
} else {
echo "Error: Can't create folder for crop image!";
}
} else
{
if(!JFolder::exists($folderPath)){
if(mkdir($folderPath, 0777)){
} else {
echo "Error: Can't create folder for crop image!";
}
}
}
$nameImg = str_replace('/','',strrchr($imagePath,"/"));
$ext = substr($nameImg, strrpos($nameImg, '.'));
$file_name = substr($nameImg, 0, strrpos($nameImg, '.'));
$nameImg = str_replace(" ","",$file_name . "_" . $width . "_" . $height . $ext);
if(!JFile::exists($folderPath.DS.$nameImg)){
$image = new SimpleImage();
$image->load($imagePath);
$image->crop($width,$height);
$image->save($folderPath.DS.$nameImg);
}else{
list($info_width, $info_height) = @getimagesize($folderPath.DS.$nameImg);
if($width!=$info_width||$height!=$info_height){
$image = new SimpleImage();
$image->load($imagePath);
$image->crop($width,$height);
$image->save($folderPath.DS.$nameImg);
}
}
return $this->url_to_crop . $nameImg;
}