dpwuvfpu52502 2017-03-05 19:21
浏览 296

ImageMagick - writeImage输出产生8位深度图像而不是24位深度图像

I am really new to this ImageMagick & GhostScript thus, I am confused what I have done wrong. I am trying to convert the cover page of the PDF to JPG, but some of the writeImage output, produce colored once - 24bit, and most produce mono-coloured - 8bit(Which I don't want).

My code is:


<html>
<head>
</head>
<body>
    <form action="upload.php" method="post" enctype="multipart/form-data">
        <input type="file" id="pdf" name="file" accept=".pdf"/>
        <input type="file" id="imagePDF" style="display:none">
        <input type="submit" value="upload"/>
    </form>
</body>


<?php
if(isset($_FILES['file'])){

    //Save file to directory
    $file = $_FILES['file'];
    $file_destination = "files/";
    //File properties
    $file_name = $file['name'];
    $file_tmp = $file['tmp_name'];
    $file_size = $file['size'];
    $file_error = $file['error'];

    //Work out the file extension
    $file_ext = explode('.', $file_name);
    $file_ext = strtolower(end($file_ext));

    $allowed = array('pdf');

    if(in_array($file_ext, $allowed)){
        if($file_error === 0){
            if($file_size <= 63000000){
                //File destination relative to upload.php
                $pdfWithPath = $file_destination . $file_name;
                if(move_uploaded_file($file_tmp, $pdfWithPath)){
                    echo("File uploaded: <br>");
                    echo $pdfWithPath;
                }

            }
        }
    }

    //Create thumbnail and save to directory
    $thumb_name = $file_name . ".jpg";
    $thumb_destination = "pdfThumb/";
    $thumb_path = $thumb_destination . $thumb_name;
    $thumb_first_page = $pdfWithPath . "[0]";

    $image = new Imagick();
    $image->readImage(__DIR__ . DIRECTORY_SEPARATOR . $thumb_first_page);
    $image->writeImage(__DIR__ . DIRECTORY_SEPARATOR .'pdfThumb/'.$thumb_name);
    $image->destroy();
    echo("Done");
}
?>

<html>
    <head>
        <!--Display image on screen -->
        <img src="<?php echo $thumb_path; ?>"/>
    </head>
    <body>
    </body>
</html>

The idea of this code is to upload the pdf and store it into the folder 'files' Then to create the thumbnail of the PDF file, it will retrieve the PDF from the folder 'files' and produce an image, saving the image to the folder 'pdfThumb'


I have 2 outcomes for this writeImage, colored and mono-coloured shown below

Mono-coloured image produced

Coloured image produce


I want to make all the images produced by the writeImage output to be all colored. How should I improve my code?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog