There are gray stains on the image after converting to another format after use ImageMagick php
Posted: 2017-01-24T08:06:52-07:00
I have the following problem. I use ImageMagick for the reformat PDF to JPG. Everything goes well but on the picture appear the mark in the form of triangles. Here is an example code and images before and after.
[1]: https://i.stack.imgur.com/Du1f8.jpg
Code: Select all
$pdf_file = $name[0] . '.pdf';
$im = new imagick($pdf_file);
$i = 0;
foreach ($im as $_img) {
$i++;
$_img->setResolution(300, 300);
$im->setImageColorspace(255);
$im->setCompression(Imagick::COMPRESSION_JPEG);
$im->setCompressionQuality(60);
$_img->setImageFormat('jpg');
$_img->writeImage(__DIR__ .'/'.$main_name[0] . '.jpg');
}
$im->destroy();
$new_name = DIR .'/'. $main_name[0] . '.jpg';
$new_name1 = $main_name[0] . '.jpg';
//$new_name1 = preg_replace('/[^A-Za-z0-9\-]/', '', $new_name1);
$size = getimagesize($new_name1);
$ratio = $size[0]/$size[1]; // width/height
if( $ratio > 1) {
$width = 700;
$height = 700/$ratio;
}
else {
$width = 700*$ratio;
$height = 700;
}
$src = imagecreatefromstring(file_get_contents($new_name1));
$dst = imagecreatetruecolor($width,$height);
imagecopyresampled($dst,$src,0,0,0,0,$width,$height,$size[0],$size[1]);
imagedestroy($src);
imagepng($dst,$new_name1); // adjust format as needed
imagedestroy($dst);
[1]: https://i.stack.imgur.com/Du1f8.jpg