Imagick Vector (Pdf, Svg) to Jpg


Find best resulation and apply for all vector image.
$imagick = new Imagick();
$imagick->setResolution(100,100);
$imagick->readimage("image.svg[0]"); //or "image.pdf[0]"
/* Apply Best Resolution */
$geo=$imagick->getImageGeometry();
$geo_height = intval($geo['height']);
$geo_width = intval($geo['width']);
if ($geo_width > 800 || $geo_height > 800) {
    //do not do anything if one of them is larger than 800px
}
else {
    if ($geo_width > $geo_height) {
        $r = round(800 / $geo_width) * 150;
    }
    else {
        $r = round(800 / $geo_height) * 150;
    }
    //readimage with new resolution
    $imagick->setResolution($r,$r);
    $imagick->readimage("image.svg[0]");
}
/* Apply Best Resolution End */

Yorumlar