2017-08-03 4 views
1

En utilisant l'exemple de Croppic, je continue à me retrouver avec des bordures sur un ou plusieurs côtés d'une image lorsque je recadre des images. Exemple:Le recadrage de recadrage PHP crée une bordure

enter image description here

Voici le code que je utilise pour traiter l'image:

 // original sizes 
    $imgInitW = $request->get('imgInitW'); 
    $imgInitH = $request->get('imgInitH'); 
    // resized sizes 
    $imgW = $request->get('imgW'); 
    $imgH = $request->get('imgH'); 
    // offsets 
    $imgY1 = $request->get('imgY1'); 
    $imgX1 = $request->get('imgX1'); 
    // crop box 
    $cropW = $request->get('cropW'); 
    $cropH = $request->get('cropH'); 
    // rotation angle 

    $output_filename = sys_get_temp_dir() . "/croppedImg_" . rand(); 

    $source_image = imagecreatefromjpeg($media->getPath()); 

    $type = '.jpeg'; 

    // resize the original image to size of editor 
    $resizedImage = imagecreatetruecolor($imgW, $imgH); 

    imagecopyresampled($resizedImage, $source_image, 0, 0, 0, 0, $imgW, $imgH, $imgInitW, $imgInitH); 

    // rotate the rezized image 
    $rotated_image = imagerotate($resizedImage, -$angle, 0); 
    // find new width & height of rotated image 
    $rotated_width = imagesx($rotated_image); 
    $rotated_height = imagesy($rotated_image); 
    // 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); 
    // 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); 
    // finally output png image 
    //imagepng($final_image, $output_filename.$type, $png_quality); 
    imagejpeg($final_image, $output_filename . $type, '100'); 

Cela se produit généralement que lorsque je réduis l'image autant que possible dans le croppic window. Je suis à perte et j'ai essayé d'ajuster tous les paramètres que je peux trouver. Des idées?

Répondre

0

J'ai effectivement trouvé la réponse here. J'ai appliqué la version fourchue et cela fonctionne.