Slawlos
(Smale)
21 Marzec 2007 22:18
#1
Czy ktoś wie jak wyświetlić obrazek .tif na stronie internetowej?
Konwersji na inne formaty wolałbym uniknąć z różnych względów.
Głównie dlatego że w takim formacie są te dane i takie muszą pozostać.
Do dyspozycji funkcje php no ale nie widze tam obsługi plików tiff.
jakieś pomysły ?
adpawl
(adpawl)
21 Marzec 2007 22:48
#2
Zobacz, fragment z manuala …tu akurat przykład konwersji, ale spoko można imagemagic’a do tego wykorzystać:
\<a href='http://php.net/gd'\>http://php.net/gd\</a\>:
tfl at netcabo dot pt 18-Aug-2005 03:48 IE doesn’t show TIFF files and standard PHP distribution doesn’t support converting to/from TIFF. ImageMagick (http://www.imagemagick.org/script/index.php ) is a free software that can read, convert and write images in a large variety of formats. For Windows users it includes a PHP extension php_magickwand_st.dll (and yes, it runs under PHP 5.0.4). 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”; 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”; 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 x_res=$x_res $units - y_res=$y_res $units”; 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 “”; echo “$file = width=$width - height=$height - type=$type - attr=$attr”; $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 “”; echo “$file = width=$width - height=$height - type=$type - attr=$attr”; ? Note - Although ImageMagick correctly sets JPEG files resolution to 300 DPIs, some programs might not notice it.
Slawlos
(Smale)
21 Marzec 2007 22:55
#3
dzieki, popatrze
powiedz mi jeszcze jak ją zainstalowac w php
na stronie http://www.magickwand.org/download/php/
byly dla php dwie biblioteki
php_magickwand_dyn.dll
php_magickwand_q16_st.dll
dokladam je w php.ini jednak po restarcie nie chce mi serwer ładować żadnej z nich
Ryan
(Ryan)
22 Marzec 2007 02:26
#4
Masz kilka opcji, najprostszą jest w/w konwersja w locie. Przedlądarka nie wyświetla TIFów. Inna opcja to napisanie wtyczki dla przeglądarki(ek), która TIFy wyświetla.
Co rozumiesz jako “nie chce Ci załadować”? Loguje jakiś błąd, czy nie widzisz, żeby działały? Gdzie umieszczasz pliki, jakie masz wpisy w php.ini, gdzie masz umieszczone php.ini?
Slawlos
(Smale)
22 Marzec 2007 08:47
#5
Wpis w php.ini jest taki
extension=php_magickwand_q16_st.dll l
ub
extension=php_magickwand_dyn.dll
(testowalem obe biblioteki)
pliki są wrzucone do C:\apache\php\extensions tam gdzie i inne moduły
w pierwszym przypadku mam komunikat:
PHP Starup: magicwand: Unable to initialize module
Module compiled with module API=20060613, debug=0,thread-safety=1
PHP compiled with module API=20050922, debug=0, thread-safety=1
These options need to match
w drugim zaś:
PHP Statup: Unable to load dynamic library 'C:\apache\php\extensions\php_magickwand_q16_st.dll' - Nie można odnależć określonego modułu.
mam php w wersji 5.1.2
Złączono Posta : 22.03.2007 (Czw) 21:45
ok , problem rozwiązany
pomogło zainstalowanie najnowszego php