I want to replace all the GD code with imagick code from the "cropping jquery plugin" from www.croppic.net
Here is the original file https://github.com/sconsult/croppic/blob/master/img_crop_to_file.php
what I have done
// original sizes
$imgInitW = $_POST['imgInitW'];
$imgInitH = $_POST['imgInitH'];
// resized sizes
$imgW = $_POST['imgW'];
$imgH = $_POST['imgH'];
// offsets
$imgY1 = $_POST['imgY1'];
$imgX1 = $_POST['imgX1'];
// crop box
$cropW = $_POST['cropW'];
$cropH = $_POST['cropH'];
// rotation angle
$angle = $_POST['rotation'];
//quali
$jpeg_quality = 100;
/* resize the original image to size of editor */
// $imgUrl = '/kunden/40/0_org.jpg';
// $img_r = imagecreatefromjpeg($imgUrl);
// $source_image = imagecreatefromjpeg($imgUrl);
// $type = '.jpeg';
// $resizedImage = imagecreatetruecolor($imgW, $imgH);
// imagecopyresampled($resizedImage, $source_image, 0, 0, 0, 0, $imgW, $imgH, $imgInitW, $imgInitH);
$im = new imagick('/kunden/40/0_org.jpg');
$im->resizeImage($imgW, $imgH, 0, 0, false);
/* rotate the rezized image */
// $rotated_image = imagerotate($resizedImage, -$angle, 0);
$im->rotateimage('#fff', -$angle);
/* find new width & height of rotated image */
// $rotated_width = imagesx($rotated_image);
// $rotated_height = imagesy($rotated_image);
$d = $im->getImageGeometry();
$rotated_width = $d['width'];
$rotated_height = $d['height'];
/* diff between rotated & original sizes */
$dx = $rotated_width - $imgW;
$dy = $rotated_height - $imgH;
/* crop rotated image to fit into original rezized rectangle */
// $cropped_rotated_image = imagecreatetruecolor($imgW, $imgH);
// imagecolortransparent($cropped_rotated_image, imagecolorallocate($cropped_rotated_image, 0, 0, 0));
// imagecopyresampled($cropped_rotated_image, $rotated_image, 0, 0, $dx / 2, $dy / 2, $imgW, $imgH, $imgW, $imgH);
$im->cropImage($imgW,$imgH, $dx/2, $dy/2); // i think this is not correct
/* crop image into selected area */
// $final_image = imagecreatetruecolor($cropW, $cropH);
// imagecolortransparent($final_image, imagecolorallocate($final_image, 0, 0, 0));
// imagecopyresampled($final_image, $cropped_rotated_image, 0, 0, $imgX1, $imgY1, $cropW, $cropH, $cropW, $cropH);
/* save image */
// imagejpeg($final_image, $output_filename.'.jpg', $jpeg_quality);
$im->writeImage('/kunden/40/0.jpg');
The result is an black image with an incorrect width and height. Hope somebody can help me. Thanks in advance!