diff options
| author | Max Kremmel <xing@synapse.plus.com> | 2007-09-25 15:36:09 +0000 |
|---|---|---|
| committer | Max Kremmel <xing@synapse.plus.com> | 2007-09-25 15:36:09 +0000 |
| commit | d5b644bbc19898ac5b1d68daecdc64145554893b (patch) | |
| tree | e0ac74f2bcfd59e0bd0bf79405a2cb85aca77991 | |
| parent | 5c8e2c3c54e08943751c322e63b4adc6a26f4832 (diff) | |
| download | liberty-d5b644bbc19898ac5b1d68daecdc64145554893b.tar.gz liberty-d5b644bbc19898ac5b1d68daecdc64145554893b.tar.bz2 liberty-d5b644bbc19898ac5b1d68daecdc64145554893b.zip | |
clean up image processing admin options, add preliminary support for php-imagick > 2.0 with the new API. this pecl extension is still in beta and still seems to be missing some error methods. please keep an eye on this processor as new versions of php-imagick are released
| -rw-r--r-- | admin/admin_liberty_inc.php | 25 | ||||
| -rw-r--r-- | plugins/processor.imagick.php | 166 | ||||
| -rw-r--r-- | plugins/processor.magickwand.php | 8 | ||||
| -rw-r--r-- | templates/admin_liberty.tpl | 78 |
4 files changed, 194 insertions, 83 deletions
diff --git a/admin/admin_liberty_inc.php b/admin/admin_liberty_inc.php index f1de0ee..2c3b864 100644 --- a/admin/admin_liberty_inc.php +++ b/admin/admin_liberty_inc.php @@ -58,6 +58,31 @@ $attachmentStyleOptions = array( $gBitSmarty->assign( 'attachmentStyleOptions', $attachmentStyleOptions ); +$imageProcessors = array( + 'gd' => array( + 'installed' => ( extension_loaded( 'gd' ) ? TRUE : FALSE ), + 'install_note' => 'The GD library is not installed. For newer Linux systems (Fedora, etc.), you need to install the php-gd package with a command such as "yum install php-gd".', + 'label' => 'PHP - GD', + 'note' => 'The GD libraries are usually readily available but do not support as many image types as the other image processors. If you plan on uploading many images to your server, please consider using one of the more advanced image porcessors.', + ), + 'imagick' => array( + 'installed' => ( extension_loaded( 'imagick' ) ? TRUE : FALSE ), + 'install_note' => 'The pecl imagick extension has recently been updated to version 2.0, which is still in the early phases of devlopment. We will automaigically make use of the correct installed version but please note that the 2.* version is still in beta and might not work well depending on the build you have. Many distributions have php-imagick available through their package manager. Try something like: yum install php-imagick or emerge dev-php5/pecl-imagick. You can get the latest version here: <a href="http://pecl.php.net/package/imagick">Pecl :: Package :: imagick</a>', + 'label' => 'PHP - Imagick', + 'note' => 'This pecl extension is a popular and frequently used extension. This extension is recommended and works with most image types. We support the older version 0.* and the new 2.* extension (please note that version 2.* is still in beta and some versions might not work as well as others).', + 'recommended' => TRUE, + ), + 'magickwand' => array( + 'installed' => extension_loaded( 'magickwand' ) ? TRUE : FALSE, + 'install_note' => 'To use MagickWand, you need to install the magickwand php extension. Unix and Windows users can find source code at <a href="http://www.magickwand.org/download/php/">the ImageMagick downloads website.</a>.', + 'label' => 'PHP - Magickwand', + 'note' => 'The PHP imagick pecl extension is a rather new interface between PHP and ImageMagick. It is probably the best of the currently available image processing extensions.', + 'recommended' => TRUE, + ), +); +$gBitSmarty->assign( 'imageProcessors', $imageProcessors ); + + $cacheTimes = array( 0 => tra( "(no cache)" ), 3600 => "1 ".tra( "hour" ), diff --git a/plugins/processor.imagick.php b/plugins/processor.imagick.php index 2505424..252d3b6 100644 --- a/plugins/processor.imagick.php +++ b/plugins/processor.imagick.php @@ -1,6 +1,6 @@ <?php /** - * $Header: /cvsroot/bitweaver/_bit_liberty/plugins/processor.imagick.php,v 1.4 2007/07/29 14:23:25 squareing Exp $ + * $Header: /cvsroot/bitweaver/_bit_liberty/plugins/processor.imagick.php,v 1.5 2007/09/25 15:36:09 squareing Exp $ * * Image processor - extension: php-imagick * @package liberty @@ -15,6 +15,68 @@ * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure */ function liberty_imagick_resize_image( &$pFileHash, $pThumbnail = FALSE ) { + if( $func = liberty_imagick_get_function( 'resize_image' )) { + return $func( $pFileHash, $pThumbnail ); + } +} + +/** + * liberty_imagick_rotate_image + * + * @param array $pFileHash + * @access public + * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure + */ +function liberty_imagick_rotate_image( &$pFileHash ) { + if( $func = liberty_imagick_get_function( 'rotate_image' )) { + return $func( $pFileHash, $pThumbnail ); + } +} + +/** + * liberty_imagick_can_thumbnail_image + * + * @param array $pMimeType + * @access public + * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure + */ +function liberty_imagick_can_thumbnail_image( $pMimeType ) { + $ret = FALSE; + if( !empty( $pMimeType ) ) { + $ret = preg_match( '/(^image|pdf$|postscript$)/i', $pMimeType ); + } + return $ret; +} + +/** + * liberty_imagick_get_function will automagically pick the correct function based on the version of imagick extension installed + * + * @return valid function. + */ +function liberty_imagick_get_function( $pFunction ) { + $ret = FALSE; + if( extension_loaded( 'imagick' )) { + if( function_exists( 'imagick_readimage' )) { + $version = 0; + } elseif( class_exists( 'Imagick' )) { + $version = 2; + } + } + + if( isset( $version ) && !empty( $pFunction )) { + $func = 'liberty_imagick'.$version.'_'.$pFunction; + if( function_exists( $func )) { + $ret = $func; + } + } + return $ret; +} + + +// ============================================= +// ======== Version 0.9* of php-imagick ======== +// ============================================= +function liberty_imagick0_resize_image( &$pFileHash, $pThumbnail = FALSE ) { global $gBitSystem; $pFileHash['error'] = NULL; $ret = NULL; @@ -90,14 +152,7 @@ function liberty_imagick_resize_image( &$pFileHash, $pThumbnail = FALSE ) { return $ret; } -/** - * liberty_imagick_rotate_image - * - * @param array $pFileHash - * @access public - * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure - */ -function liberty_imagick_rotate_image( &$pFileHash ) { +function liberty_imagick0_rotate_image( &$pFileHash ) { $ret = FALSE; if( !empty( $pFileHash['source_file'] ) && is_file( $pFileHash['source_file'] ) ) { $iImg = imagick_readimage( $pFileHash['source_file'] ); @@ -122,18 +177,89 @@ function liberty_imagick_rotate_image( &$pFileHash ) { return( empty( $pFileHash['error'] ) ); } -/** - * liberty_imagick_can_thumbnail_image - * - * @param array $pMimeType - * @access public - * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure - */ -function liberty_imagick_can_thumbnail_image( $pMimeType ) { - $ret = FALSE; - if( !empty( $pMimeType ) ) { - $ret = preg_match( '/(^image|pdf$|postscript$)/i', $pMimeType ); + + +// ============================================ +// ======== Version 2.* of php-imagick ======== +// ============================================ +function liberty_imagick2_resize_image( &$pFileHash, $pThumbnail = FALSE ) { + global $gBitSystem; + $pFileHash['error'] = NULL; + $ret = NULL; + if( !empty( $pFileHash['source_file'] ) && is_file( $pFileHash['source_file'] )) { + $im = new Imagick(); + $im->readImage( $pFileHash['source_file'] ); + if( !$im->valid()) { + $destUrl = liberty_process_generic( $pFileHash, FALSE ); + } else { + $im->setCompressionQuality( 85 ); + $iwidth = $im->getImageWidth(); + $iheight = $im->getImageHeight(); + if((( $iwidth / $iheight ) > 0 ) && !empty( $pFileHash['max_width'] ) && !empty( $pFileHash['max_height'] )) { + // we have a portrait image, flip everything + $temp = $pFileHash['max_width']; + $pFileHash['max_height'] = $pFileHash['max_width']; + $pFileHash['max_width'] = $temp; + } + + // override $mimeExt if we have a custom setting for it + if( $gBitSystem->isFeatureActive( 'liberty_thumbnail_format' )) { + $mimeExt = $gBitSystem->getConfig( 'liberty_thumbnail_format' ); + } else { + list( $type, $mimeExt ) = split( '/', strtolower( $pFileHash['type'] )); + } + + if( preg_match( "!(png|gif)!", $mimeExt )) { + $targetType = $mimeExt; + $destExt = '.'.$mimeExt; + } else { + $targetType = 'jpeg'; + $destExt = '.jpg'; + } + + if( !empty( $pFileHash['max_width'] ) && !empty( $pFileHash['max_height'] ) && (( $pFileHash['max_width'] < $iwidth || $pFileHash['max_height'] < $iheight ) || $mimeExt != $targetType )) { + $destUrl = $pFileHash['dest_path'].$pFileHash['dest_base_name'].$destExt; + $destFile = BIT_ROOT_PATH.'/'.$destUrl; + $pFileHash['name'] = $pFileHash['dest_base_name'].$destExt; + + // create thumb and write + $im->thumbnailImage( $pFileHash['max_width'], NULL ); + $im->writeImage( $destFile ); + + $pFileHash['size'] = filesize( $destFile ); + } else { + $destUrl = liberty_process_generic( $pFileHash, FALSE ); + } + } + + // destroy object + $im->destroy(); + + $ret = $destUrl; + } else { + $pFileHash['error'] = "No source file to resize"; } + return $ret; } + +function liberty_imagick2_rotate_image( &$pFileHash ) { + $ret = FALSE; + if( !empty( $pFileHash['source_file'] ) && is_file( $pFileHash['source_file'] )) { + $im = new Imagick(); + $im->readImage( $pFileHash['source_file'] ); + if( !$im->valid()) { + $destUrl = liberty_process_generic( $pFileHash, FALSE ); + } elseif( empty( $pFileHash['degrees'] ) || !is_numeric( $pFileHash['degrees'] )) { + $pFileHash['error'] = tra( 'Invalid rotation amount' ); + } else { + $im->rotateImage( new ImagickPixel(), $pFileHash['degrees'] ); + $im->writeImage( $pFileHash['source_file'] ); + } + } else { + $pFileHash['error'] = "No source file to resize"; + } + + return( empty( $pFileHash['error'] )); +} ?> diff --git a/plugins/processor.magickwand.php b/plugins/processor.magickwand.php index 7517bc5..0da769b 100644 --- a/plugins/processor.magickwand.php +++ b/plugins/processor.magickwand.php @@ -1,6 +1,6 @@ <?php /** - * $Header: /cvsroot/bitweaver/_bit_liberty/plugins/processor.magickwand.php,v 1.10 2007/07/29 14:23:25 squareing Exp $ + * $Header: /cvsroot/bitweaver/_bit_liberty/plugins/processor.magickwand.php,v 1.11 2007/09/25 15:36:09 squareing Exp $ * * Image processor - extension: php-magickwand * @package liberty @@ -47,6 +47,8 @@ function liberty_magickwand_resize_image( &$pFileHash, $pThumbnail = FALSE ) { MagickSetImageCompressionQuality( $magickWand, 85 ); $iwidth = round( MagickGetImageWidth( $magickWand ) ); $iheight = round( MagickGetImageHeight( $magickWand ) ); + vd($iwidth); + vd($iheight); // this does not seem to be needed. magickwand will work out what to do by using the destination file extension //MagickSetImageFormat( $magickWand, $format ); @@ -54,13 +56,13 @@ function liberty_magickwand_resize_image( &$pFileHash, $pThumbnail = FALSE ) { if( empty( $pFileHash['max_width'] ) || empty( $pFileHash['max_height'] ) || $pFileHash['max_width'] == MAX_THUMBNAIL_DIMENSION || $pFileHash['max_height'] == MAX_THUMBNAIL_DIMENSION ) { $pFileHash['max_width'] = $iwidth; $pFileHash['max_height'] = $iheight; - } elseif( (($iwidth / $iheight) < 1) && !empty( $pFileHash['max_width'] ) && !empty( $pFileHash['max_height'] ) ) { + } elseif(( $iwidth / $iheight ) < 1 && !empty( $pFileHash['max_width'] ) && !empty( $pFileHash['max_height'] )) { // we have a portrait image, flip everything $temp = $pFileHash['max_width']; $pFileHash['max_height'] = $pFileHash['max_width']; $pFileHash['max_width'] = round( ($iwidth / $iheight) * $pFileHash['max_height'] ); } elseif( !empty( $pFileHash['max_width'] ) ) { - $pFileHash['max_height'] = round( ($iheight / $iwidth) * $pFileHash['max_width'] ); + $pFileHash['max_height'] = round(( $iheight / $iwidth ) * $pFileHash['max_width'] ); } // Make sure not to scale up diff --git a/templates/admin_liberty.tpl b/templates/admin_liberty.tpl index ef82766..c49b530 100644 --- a/templates/admin_liberty.tpl +++ b/templates/admin_liberty.tpl @@ -74,68 +74,26 @@ {jstab title="Image Processing System"} {legend legend="Image Processing System"} <input type="hidden" name="page" value="{$page}" /> - {php}if( extension_loaded( 'gd' ) ) {{/php}{assign var=gdInstalled value=TRUE}{php}}{/php} - {if !$gdInstalled} - {formfeedback warning='The GD library is not installed. For newer Linux systems (Fedora, etc.), you need to install the php-gd RPM with a command such as "yum install php-gd".'} - {/if} - <div class="row"> - {formlabel label="GD library" for="gd"} - {forminput} - <label> - <input type="radio" id="gd" name="image_processor" value="gd" {if !$gdInstalled}disabled="disabled"{/if} {if !$gBitSystem->getConfig('image_processor') || $gBitSystem->getConfig('image_processor')=='gd'}checked="checked"{/if} /> - {if !$gdInstalled} - {biticon ipackage=icons iname="large/image-missing" iexplain="Not Installed"} {tr}Library is <strong>not</strong> installed{/tr} - {else} - {biticon ipackage=icons iname="large/image-x-generic" iexplain="Installed"} {tr}Library is installed{/tr} - {/if} - </label> - {formhelp note="The GD libaries are quite limited and <strong>don't support</strong> a number of image formats including <strong>bmp</strong>. If you are planning on uploading and using a lot of images, we recommend you use one of the other image processors."} - {/forminput} - </div> - - {php}if( extension_loaded( 'magickwand' ) ) {{/php}{assign var=magickwandInstalled value=TRUE}{php}}{/php} - {if !$magickwandInstalled} - {formfeedback warning='To use MagickWand, you need to install the magickwand php extension. Unix and Windows users can find source code at <a href="http://www.magickwand.org/download/php/">the ImageMagick downloads website.</a>.'} - {/if} - <div class="row"> - {formlabel label="ImageMagick MagickWand" for="wand"} - {forminput} - <label> - <input type="radio" id="wand" name="image_processor" value="magickwand" {if !$magickwandInstalled}disabled="disabled"{/if} {if $gBitSystem->getConfig('image_processor')=='magickwand'}checked="checked"{/if}/> - {if !$magickwandInstalled} - {biticon ipackage=icons iname="large/image-missing" iexplain="Not Installed"} {tr}Library is <strong>not</strong> installed{/tr} - {else} - {biticon ipackage=icons iname="large/image-x-generic" iexplain="Installed"} {tr}Library is installed{/tr} - {/if} - </label> - {formhelp note="MagickWand is the recommended image processor and supports a multitude of different image and video formats. Using these libraries will allow you to upload most image formats without any difficulties."} - {if $magickwandInstalled} - {formhelp note=' For installation help, please view our online documentation: <a class="external" href="http://www.bitweaver.org/wiki/ImageMagick">ImageMagick and MagickWand installation instructions</a> or visit the <a class="external" href="http://www.imagemagick.org">ImageMagick</a> homepage.'} - {/if} - {/forminput} - </div> + {foreach from=$imageProcessors key=item item=output} + <div class="row"> + {formlabel label=`$output.label` for=$item} + {forminput} + <label> + <input type="radio" id="{$item}" name="image_processor" value="{$item}" {if !$output.installed}disabled="disabled"{/if} {if $gBitSystem->getConfig('image_processor','gd') == $item}checked="checked"{/if} /> + {if !$output.installed} + {biticon ipackage=icons iname="large/image-missing" iexplain="Not Installed"} {tr}Library is <strong>not</strong> installed{/tr} + {else} + {biticon ipackage=icons iname="large/image-x-generic" iexplain="Installed"} {tr}Library is installed{/tr} + {/if} + </label> - {php}if( extension_loaded( 'imagick' ) ) {{/php}{assign var=imagickInstalled value=TRUE}{php}}{/php} - {if !$imagickInstalled} - {formfeedback warning='php-imagick is a no longer supported PECL extension for PHP + ImageMagick. We recommend using the much better supported magickwand option above. If you need to install the php-imagick extension, linux users can find RPM files at <a href="http://phprpms.sourceforge.net/imagick">PHPRPMs</a> (or compile a <a href="http://sourceforge.net/project/showfiles.php?group_id=112092&package_id=139307&release_id=292417">source rpm</a>). Windows users can try <a href="http://www.bitweaver.org/builds/php_imagick.dll">this dll</a> however it has not been tested well.'} - {/if} - <div class="row"> - {formlabel label="ImageMagick PHP-iMagick" for="magick"} - {forminput} - <label> - <input type="radio" id="magick" name="image_processor" value="imagick" {if !$imagickInstalled}disabled="disabled"{/if} {if $gBitSystem->getConfig('image_processor')=='imagick'}checked="checked"{/if}/> - {if !$imagickInstalled} - {biticon ipackage=icons iname="image-missing" iexplain="Not Installed"} {tr}Library is <strong>not</strong> installed{/tr} - {else} - {biticon ipackage=icons iname="large/image-x-generic" iexplain="Installed"} {tr}Library is installed{/tr} + {if !$output.installed} + {formhelp note=`$output.install_note` page=`$output.page`} {/if} - </label> - {formhelp note="ImageMagick supports a multitude of different image and video formats. Using these libraries will allow you to upload most image formats without any difficulties."} - {if !$imagickInstalled} - {formhelp note=' For installation help, please view our online documentation: <a class="external" href="http://www.bitweaver.org/wiki/ImageMagick">ImageMagick and MagickWand installation instructions</a> or visit the <a class="external" href="http://www.imagemagick.org">ImageMagick</a> homepage.'} - {/if} - {/forminput} - </div> + {formhelp note=`$output.note` page=`$output.page`} + {/forminput} + </div> + {/foreach} {foreach from=$formImageFeatures key=item item=output} <div class="row"> |
