imagick creates wrong colorspace / colors -
i have following code on site have create images out of uploaded pdf files, problem cannot colors right (and yes there can both text , images in pdf files):
$img = new imagick(); $img->setresolution(72, 72); $img->readimage($dir_f.$file); $img->set imagecompression(imagick::compression_no); $img->setimagecompressionquality(100); $num_pages = $img->getnumberimages(); for($i = 0;$i < $num_pages; $i++) { $fina l_name = str_replace(" ", "+", basename(str_replace(".".$file_ext,"", $file_name))); $final_name = preg_replace("/[^a-za-z0-9-+]/", "", $final_name); $save_to = $pdf_dir."/".str_replace(".".$file_ext,"", $final_name).'-'.$i.'.png'; $img->setiteratorindex($i); $img->setimagecompression(imagick::compression_no); $img->setimagecompressionquality(100); $img->setimageformat("png"); $img->writeimage($save_to); $file_image = str_replace(dirname(__file__)."/../../", "/", $save_to); $file_images[] = array($file_image, $index[$ii]); } $img->destroy();
i have gotten different results depending on wich type of colorspace have been using non of them correctly made colors.
when dont set colorspace gets bright. when use colorspace srgb or cmyk image gets bright, when use colorspace compression_no gets bright when use colorspace rgb gets dark
hopefully able me out here.
this looks it's bug in ghostscript, delegate program imagemagick uses convert pdfs bitmap format.
using ghostscript version 8.70 see same output seeing, i.e. image lighter when viewing pdf directly.
after downloading ghostscript version 9 , running command below conversion, see same colours in pdf.
you're going need either upgrade ghostscript 9 or figure out special pdf makes ghostscript not convert correctly. think pdf might either have non-standard color profile or weird colorspace. converting gs9 works fine, easiest way fix problem.
./ghostscript-9.16-linux-x86_64/gs-916-linux_x86_64 -q -dquiet -dsafer -dbatch \ -dnopause -dnoprompt -dmaxbitmap=500000000 \ -daligntopixels=0 -dgridfittt=1 -sdevice=pngalpha \ -dfirstpage=1 -dlastpage=3 \ -dtextalphabits=4 -dgraphicsalphabits=4 -r72 \ -soutputfile=gs-%d.png 153311-flyers-sample-papers-volume-2.pdf
Comments
Post a Comment