php png / jpg / bmp tiff dönüştürmek nasıl?

6 Cevap

Herhangi bir vücut, pls nasıl php diğer formata tiff resmi görüntülemek veya dönüştürmek için bana yardım et.

6 Cevap

"Imagick" PECL uzantısı kullan

http://pecl.php.net/package/imagick

http://php.net/manual/en/book.imagick.php

Kaynaklar ve hedefler bağlı (? Dosyalar URL'ler http yanıt) gibi bir şey yapacağım:

$image = new Imagick('something.tiff');
$image->setImageFormat('png');
echo $image;

VEYA

$image->writeImage('something.png');

http://www.imagemagick.org/script/index.php

Imagemagic sunucu üzerinde yüklü ise onun bu kadar basit (en unix host var) ...

<?php
$exec = "convert /path/to/file.tiff /path/to/file.jpg";
exec($exec, $yaks);
//to view any errors >> // print_r($yaks);
?>

De forumda http://www.php.net/gd, aşağıdaki açıklama yazılır:

IE TIFF dosyalar görünmüyor ve standart PHP dağıtım TIFF / konumuna dönüştürme desteklemiyor.

ImageMagick (http://www.imagemagick.org/script/index.php), okumak dönüştürmek ve biçimlerde çok çeşitli görüntüler yazabilirsiniz ücretsiz bir yazılımdır. Windows kullanıcıları için bir PHP uzantısı php_magickwand_st.dll içerir (ve evet, PHP 5.0.4 altında çalışır).

When converting from TIFF to JPEG, you must also convert from CMYK color space to RGB color space as IE can't show CMYK JPGs either. Please note: -TIFF files may have RGB or CMYK color space -JPEG files may have RGB or CMYK color space

Here are example functions using ImageMagick extension: - convert TIFF to JPEG file formats - convert CMIK to RGB color space - set image resolution to 300 DPIs (doesn't change image size in pixels)

<?php

function cmyk2rgb($file) {
    $mgck_wnd = NewMagickWand();
    MagickReadImage($mgck_wnd, $file);

    $img_colspc = MagickGetImageColorspace($mgck_wnd);
    if ($img_colspc == MW_CMYKColorspace) {
        echo "$file was in CMYK format<br />";
        MagickSetImageColorspace($mgck_wnd, MW_RGBColorspace);
    }
    MagickWriteImage($mgck_wnd, str_replace('.', '-rgb.', $file));
}

function tiff2jpg($file) {
    $mgck_wnd = NewMagickWand();
    MagickReadImage($mgck_wnd, $file);

    $img_colspc = MagickGetImageColorspace($mgck_wnd);
    if ($img_colspc == MW_CMYKColorspace) {
        echo "$file was in CMYK format<br />";
        MagickSetImageColorspace($mgck_wnd, MW_RGBColorspace);
    }
    MagickSetImageFormat($mgck_wnd, 'JPG' );
    MagickWriteImage($mgck_wnd, str_replace('.tif', '.jpg', $file));
}

function to300dpi($file) {
    $mgck_wnd = NewMagickWand();
    MagickReadImage($mgck_wnd, $file);
    $img_units = MagickGetImageUnits($mgck_wnd);
    switch ($img_units) {
        case MW_UndefinedResolution: $units= 'undefined'; break;
        case MW_PixelsPerInchResolution: $units= 'PPI'; break;
        case MW_PixelsPerCentimeterResolution: $units= 'PPcm'; break;
    }
    list($x_res, $y_res) = MagickGetImageResolution($mgck_wnd);
    echo "$file<br /> x_res=$x_res $units - y_res=$y_res $units<br />";
    if($x_res == 300 && $y_res == 300 && $img_units == MW_PixelsPerInchResolution) {return; }
    MagickSetImageResolution($mgck_wnd, 300 , 300);
    MagickSetImageUnits($mgck_wnd, MW_PixelsPerInchResolution);
    MagickWriteImage($mgck_wnd, str_replace('.', '-300.', $file));
}

$file='photos/test-cmyk.tif';
//this is a TIFF file in CMYK format with a 96 DPI resolution

cmyk2rgb($file);
$file = str_replace('.', '-rgb.', $file);

to300dpi($file);
$file = str_replace('.', '-300.', $file);

tiff2jpg($file);
$file = str_replace('.tif', '.jpg', $file);

to300dpi($file);
/* no file name changes as ImageMagick reports 300 DPIs
$file = str_replace('.', '-300.', $file);
*/

list($width, $height, $type, $attr) = getimagesize($file);
$width = $width/3;
$height = $height/3;
echo "<img src=\"http://localhost/$file\" width=\"$width\" height=\"$height\" alt=\"getimagesize() example\" />";
echo "<br />$file => width=$width - height=$height - type=$type - attr=$attr<br /><br />";

$file='photos/test-rgb.tif';
//this is a TIFF file in RGB format with a 96 DPI resolution

cmyk2rgb($file);
$file = str_replace('.', '-rgb.', $file);

to300dpi($file);
$file = str_replace('.', '-300.', $file);

tiff2jpg($file);
$file = str_replace('.tif', '.jpg', $file);

to300dpi($file);
/* no file name changes as ImageMagick reports 300 DPIs
$file = str_replace('.', '-300.', $file);
*/

list($width, $height, $type, $attr) = getimagesize($file);
$width = $width/3;
$height = $height/3;
echo "<img src=\"http://localhost/$file\" width=\"$width\" height=\"$height\" alt=\"getimagesize() example\" />";
echo "<br />$file => width=$width - height=$height - type=$type - attr=$attr<br /><br />";

?>

Not - ImageMagick doğru 300 DPI'lerde JPEG dosya çözünürlüğünü ayarlar olsa da, bazı programlar bunu fark edemeyebilirsiniz.

Aşağıdaki kodu php jpg / gif / bmp tiff dönüştürme size yardımcı olabilir. Bu LINK ile ilgili daha fazla detayı görebilirsiniz. Bu jpg minik mutiple sayfa TIFF dosya dönüştürmek isteyenler için aslında yararlıdır.

<?php
try {
    // Saving every page of a TIFF separately as a JPG thumbnail
    $images = new Imagick("testing.tif"); 

    foreach($images as $i=>$image) {
        // Providing 0 forces thumbnail Image to maintain aspect ratio
        $image->thumbnailImage(768,0);
        $image->writeImage("page".$i.".jpg");
        echo "<img src='page$i.jpg' alt='images' ></img>";
    }

    $images->clear();

} catch(Exception $e) {
    echo $e->getMessage();
}    
?>

Kullan ImageMagick - yük görüntüsü, tipi sıfırlamak ve kaydedin.

imagick benim için çalışmıyor.

Ben internette bulabildiğim tüm okudum ve şimdi Imagick'teki bıktım ve imagemagick.org ve çocuklar artık bir kurulum kılavuzu ile hazır derlenmiş dll sunmuyoruz neden ben kesinlikle anlayamıyorum, başarı olmadan, 2 tüm gün boşa ?

In general the Imagick page seems not very trustworthy: On the download page they do never explain what is the difference between the several versions. What doess static mean? They never explain. (Static means that the convert.exe does not depend on so many dlls. It only requires one external DLL, for that it has a size of 5 MB instead of 200 kb) And the explanation about the difference between Q8 and Q16 version is wrong: Q8 does NOT mean 8 Bits per pixel as the download page says. It means 8 Bit per color = 24 Bit per Pixel)

<?php
try
{
// Saving every page of a TIFF separately as a JPG thumbnail
$images = new Imagick("testing.tif"); 
foreach($images as $i=>$image) {
    // Providing 0 forces thumbnail Image to maintain aspect ratio
    $image->thumbnailImage(768,0);
    $image->writeImage("page".$i.".jpg");
    echo "<img src='page$i.jpg' alt='images' ></img>";
}
$images->clear();
}
catch(Exception $e)
{
        echo $e->getMessage();
}


?>