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

在linux/php中将原始照片转换为JPEG,php,image,image-processing,imagemagick,photo,Php,Image,Image Processing,Imagemagick,Photo,我正在开发一个照片上传应用程序,需要允许用户从相机上传原始文件(这些不是jpeg),并让服务器自动创建jpeg版本。我目前已经安装了Imagemagick,但我不认为有一种方法可以在那里实现 相机总是有新的原始格式,所以我在寻找一些最新的,命令php exec()也是一个选项 有人对原始转换有什么建议吗?实际上,正如您在这个列表中看到的,ImageMagick确实支持原始照片:(例如,NEF尼康照片和.CR2佳能照片) .CR2照片的示例代码: $im = new Imagick( 'sourc

我正在开发一个照片上传应用程序,需要允许用户从相机上传原始文件(这些不是jpeg),并让服务器自动创建jpeg版本。我目前已经安装了Imagemagick,但我不认为有一种方法可以在那里实现

相机总是有新的原始格式,所以我在寻找一些最新的,命令php exec()也是一个选项


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

实际上,正如您在这个列表中看到的,ImageMagick确实支持原始照片:(例如,NEF尼康照片和.CR2佳能照片)

.CR2照片的示例代码:

$im = new Imagick( 'source.CR2' );
$im->setImageFormat( 'jpg' );
$im->writeImage( 'result.jpg' );
$im->clear();
$im->destroy();
您可以使用exec()上传,当您转换为jpg时,您可以使用jpg“提示”来加快速度-它应该只读取创建jpg所需的数据,而不是整个文件

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

convert -define jpeg:size=128x128 input.raw -thumbnail 128x128 output.jpg
Imagemagick使用Ufraw处理原始文件,我发现使用CR2文件时,我需要稍微查看其中一个文件。我想是否支持文件取决于Ufraw delagate

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

这是我修改的delegates.xml文件,将此行中的4更改为6:

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

更容易理解

sudo apt get install ufraw ufraw批处理 然后使用UFRaw(参见手册页) 或者使用使用UFRaw的ImageMagick

转换mypic.RAF mypic.jpeg

我使用Imagick完成了完全相同的页面。我成功地将TIFF、DNG、CR2文件转换为JPEG格式。在执行此操作之前,您必须参考此视频

以下是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();

}?>

警报(“错误:请先选择一个文件!”);
location.href='/Image/1.html';
警报(“错误:文件不在TIF、TIFF、CR2、PEF、NEF或DNG中”);
location.href='/Image/1.html';
警报(“上传文件”);
函数ok()
{
location.href='/Image/1.html';
}
HTML代码。在action标签中插入您的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>

上传图像
请选择文件:


我正在使用的dcraw的更新版本不再支持-O输出文件。我发现以下替换代理可以工作:
这是我基于unix的路径,我想你也可以对windows做类似的操作,用
dcraw.exe
convert
来替换
/usr/bin/dcraw
,这可能不是你想要的。如果有人有保留元数据的替代方案,请在此处添加。谢谢您的代码。但是,
destroy()
不赞成使用
clear()