在 linux/php 中将 RAW 照片转换为 JPEG


Convert RAW photos to JPEG in linux/php

我正在开发一个照片上传应用程序,需要允许用户从相机上传原始文件(这些不是jpeg),并让服务器自动创建它们的jpeg版本。我目前安装了Imagemagick,但我认为没有办法在那里做到这一点。

相机一直在推出新的原始格式,所以我正在寻找相对最新的东西,命令 php exec() 也是一种选择。

有人对原始转换有什么建议吗?

实际上,正如您在此列表中看到的,ImageMagick 确实支持 RAW 照片:http://www.imagemagick.org/script/formats.php(例如 .NEF尼康照片和.CR2 佳能照片)。

.CR2 照片:

$im = new Imagick( 'source.CR2' );
$im->setImageFormat( 'jpg' );
$im->writeImage( 'result.jpg' );
$im->clear();
$im->destroy();

更容易

sudo apt-get install ufraw ufraw-batch

然后使用 UFRaw(参见手册页)或使用使用 UFRaw 的 ImageMagick

convert mypic.RAF mypic.jpeg

您可以使用exec()上传,并且在转换为jpg时,您可以使用jpg"提示"来加快速度 - 据说它只读取尽可能多的数据来创建jpg而不是整个文件。

从内存中,定义在图像之前的转换之后:

convert -define jpeg:size=128x128 input.raw -thumbnail 128x128 output.jpg

Imagemagick使用Uraw来处理RAW文件,我发现对于我的CR2文件,我需要稍微处理其中一个文件。我想是否支持文件取决于 Ufraw delagate。

我认为三星RAW文件是一个问题,但不仅仅是Imagemagick的问题。

这是我修改的代表.xml文件,将这一行的 4 更改为 6:

<delegate decode="dng:decode" stealth="True" command="dcraw.exe -6 -w -O &quot;%u.ppm&quot; &quot;%i&quot;"/>

我使用Imagick做了完全相同的页面。我成功地将TIFF,DNG,CR2文件转换为JPEG。在执行此操作之前,您必须参考此视频 https://www.youtube.com/watch?v=q3c6O85_LoA&index=29&list=LLkmyV_KYAFxKz9gE_fEbjTA&t=23s

下面是一个包含JavaScript,HTML和PHP的代码:

<?php
$file=$_FILES['file'];
$fname=$_FILES['file']['name'];
$ftmp=$_FILES['file']['tmp_name'];
$ferr=$_FILES['file']['error'];
$check=explode(".",$fname);
$ext=end($check);
if(!$ftmp)
{
    //echo"ERROR: Please select a file first!";
    ?>
    <html>
        <script>
            alert("ERROR: Please select a file first!");
            location.href='/Image/1.html';
        </script>
    </html>
    <?php
}
else if(!preg_match("/'.(tif|tiff|cr2|pef|nef|dng)$/i",$fname))
{
    //echo"ERROR: File is not in TIF,TIFF,CR2,PEF,NEF or DNG</br>";
    //echo"File is of $ext format";
    ?>
    <html>
        <script>
            alert("ERROR: File is not in TIF,TIFF,CR2,PEF,NEF or DNG");
            location.href='/Image/1.html';
        </script>
    </html>
    <?php
}
else
{
    //echo".$ext File uploaded";
    ?>
    <html>
        <script>
            alert("File uploaded");
        </script>
    </html>
    <?php
    $im=new Imagick($ftmp);
    $im->setImageFormat('jpg');
    file_put_contents("/var/www/html/Image/Converted/a.jpg",$im);//Path where converted image will be saved on localhost.
    ?>
    <html>
        <script>
            function ok()
            {
                location.href='/Image/1.html';
            }
        </script>
        <img src="/Image/Converted/a.jpg" height="900" width="600">
        <input type=Button Value=Done onclick="ok()">
    </html>
    <?php
    $im->clear();
    $im->destroy();
}?>

网页代码。在操作标记中插入您的 php 文件名称。

<html>
<body>
    <h1 align=center>Upload image</h1>
    <form action=*.php method=POST enctype='multipart/form-data'>
        Please select the file:<br>
        <input type=file name=file><br>
        <input type=SUBMIT value=Submit>
        <input type=Reset value=Reset>
    </form>
</body>