summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorMax Kremmel <xing@synapse.plus.com>2007-06-23 17:29:57 +0000
committerMax Kremmel <xing@synapse.plus.com>2007-06-23 17:29:57 +0000
commitb71dfd54a3106e349bab643d8997b4bd71a6d15e (patch)
treebafcb35195dab1088fe2d25eda780cdafc7b0b96 /plugins
parenta3bd07cddce1b45811e0122de1502477d57579cc (diff)
downloadliberty-b71dfd54a3106e349bab643d8997b4bd71a6d15e.tar.gz
liberty-b71dfd54a3106e349bab643d8997b4bd71a6d15e.tar.bz2
liberty-b71dfd54a3106e349bab643d8997b4bd71a6d15e.zip
automagically select best image type that's best for the particular upladed file, allow override of file types and use liberty thumbnail fetcher where possible
Diffstat (limited to 'plugins')
-rw-r--r--plugins/processor.gd.php85
-rw-r--r--plugins/processor.imagick.php33
-rw-r--r--plugins/processor.magickwand.php37
3 files changed, 84 insertions, 71 deletions
diff --git a/plugins/processor.gd.php b/plugins/processor.gd.php
index 9e24b51..8a21c5b 100644
--- a/plugins/processor.gd.php
+++ b/plugins/processor.gd.php
@@ -1,6 +1,6 @@
<?php
/**
- * $Header: /cvsroot/bitweaver/_bit_liberty/plugins/processor.gd.php,v 1.2 2007/02/16 17:09:00 nickpalmer Exp $
+ * $Header: /cvsroot/bitweaver/_bit_liberty/plugins/processor.gd.php,v 1.3 2007/06/23 17:29:57 squareing Exp $
*
* Image processor - extension: php-gd
* @package liberty
@@ -11,11 +11,10 @@
* liberty_gd_resize_image
*
* @param array $pFileHash
- * @param array $pFormat
* @access public
* @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
*/
-function liberty_gd_resize_image( &$pFileHash, $pFormat = NULL, $pThumbnail = false ) {
+function liberty_gd_resize_image( &$pFileHash, $pThumbnail = FALSE ) {
global $gBitSystem;
$ret = NULL;
list($iwidth, $iheight, $itype, $iattr) = @getimagesize( $pFileHash['source_file'] );
@@ -70,48 +69,52 @@ function liberty_gd_resize_image( &$pFileHash, $pFormat = NULL, $pThumbnail = fa
$t = imagecreate($tw, $ty);
$imagegallib->ImageCopyResampleBicubic($t, $img, 0, 0, 0, 0, $tw, $ty, $size_x, $size_y);
}
- switch( $pFormat ) {
- case 'png':
- $ext = '.png';
- $destFile = BIT_ROOT_PATH.'/'.$destUrl.$ext;
- imagepng( $t, $destFile );
- // set permissions if possible - necessary for some wonky shared hosting environments
- if(chmod($pFileHash['source_file'], 0644)){
- // does nothing, but fails elegantly
- }
- break;
- case 'gif':
- // This must go immediately before default so default will be hit for PHP's without gif support
- if( function_exists( 'imagegif' ) ) {
- $ext = '.gif';
- $destFile = BIT_ROOT_PATH.'/'.$destUrl.$ext;
- imagegif( $t, $destFile );
- // set permissions if possible - necessary for some wonky shared hosting environments
- if(chmod($pFileHash['source_file'], 0644)){
- // does nothing, but fails elegantly
+
+
+ // override $mimeExt if we have a custom setting for it
+ if( $gBitSystem->isFeatureActive( 'liberty_thumbnail_format' )) {
+ $mimeExt = $gBitSystem->getConfig( 'liberty_thumbnail_format' );
+ } else {
+ // we need to interpret the value in $itype
+ $mimeExt = image_type_to_extension( $itype, FALSE );
+ }
+
+ if( preg_match( "!(png|gif)!", $mimeExt )) {
+ $targetType = $mimeExt;
+ $destExt = '.'.$mimeExt;
+ } else {
+ $targetType = 'jpeg';
+ $destExt = '.jpg';
+ }
+
+ switch( $targetType ) {
+ case 'png':
+ if( imagetypes() & IMG_PNG ) {
+ $destFile = BIT_ROOT_PATH.'/'.$destUrl.$destExt;
+ imagepng( $t, $destFile );
+ break;
}
- break;
- }
- default:
- if ($pThumbnail && $gBitSystem->isFeatureActive('liberty_png_thumbnails')) {
- $ext = '.png';
- $destFile = BIT_ROOT_PATH.'/'.$destUrl.$ext;
- imagepng( $t, $destFile );
- }
- else {
- $ext = '.jpg';
- $destFile = BIT_ROOT_PATH.'/'.$destUrl.$ext;
+ case 'gif':
+ // This must go immediately before default so default will be hit for PHP's without gif support
+ if( imagetypes() & IMG_GIF ) {
+ $destFile = BIT_ROOT_PATH.'/'.$destUrl.$destExt;
+ imagegif( $t, $destFile );
+ break;
+ }
+ default:
+ $destFile = BIT_ROOT_PATH.'/'.$destUrl.$destExt;
imagejpeg( $t, $destFile );
- }
-
- if(chmod($destFile, 0644)){
- // does nothing, but fails elegantly
- }
- break;
+ break;
}
- $pFileHash['name'] = $pFileHash['dest_base_name'].$ext;
+
+ // set permissions if possible - necessary for some wonky shared hosting environments
+ if( chmod( $pFileHash['source_file'], 0644 )){
+ // does nothing, but fails elegantly
+ }
+
+ $pFileHash['name'] = $pFileHash['dest_base_name'].$destExt;
$pFileHash['size'] = filesize( $destFile );
- $ret = $destUrl.$ext;
+ $ret = $destUrl.$destExt;
} elseif( $iwidth && $iheight ) {
$ret = liberty_process_generic( $pFileHash, FALSE );
}
diff --git a/plugins/processor.imagick.php b/plugins/processor.imagick.php
index 1c2884c..7b0c76b 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.2 2007/02/16 17:08:59 nickpalmer Exp $
+ * $Header: /cvsroot/bitweaver/_bit_liberty/plugins/processor.imagick.php,v 1.3 2007/06/23 17:29:57 squareing Exp $
*
* Image processor - extension: php-imagick
* @package liberty
@@ -11,11 +11,10 @@
* liberty_imagick_resize_image
*
* @param array $pFileHash
- * @param array $pFormat
* @access public
* @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
*/
-function liberty_imagick_resize_image( &$pFileHash, $pFormat = NULL , $pThumbnail = false) {
+function liberty_imagick_resize_image( &$pFileHash, $pThumbnail = FALSE ) {
global $gBitSystem;
$pFileHash['error'] = NULL;
$ret = NULL;
@@ -37,17 +36,25 @@ function liberty_imagick_resize_image( &$pFileHash, $pFormat = NULL , $pThumbnai
$pFileHash['max_height'] = $pFileHash['max_width'];
$pFileHash['max_width'] = $temp;
}
+
$itype = imagick_getmimetype( $iImg );
- list($type, $mimeExt) = split( '/', strtolower( $itype ) );
- if ($pThumbnail && $gBitSystem->isFeatureActive('liberty_png_thumbnails')) {
- $targetType = 'png';
- $destExt = '.png';
- }
- else {
- $targetType = 'jpeg';
- $destExt = '.jpg';
- }
- if( !empty( $pFileHash['max_width'] ) && !empty( $pFileHash['max_height'] ) && ( ($pFileHash['max_width'] < $iwidth || $pFileHash['max_height'] < $iheight ) || ($mimeExt != $targetType)) ) {
+
+ // 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( $itype ));
+ }
+
+ 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 )) {
// We have to resize. *ALL* resizes are converted to jpeg or png
$destUrl = $pFileHash['dest_path'].$pFileHash['dest_base_name'].$destExt;
$destFile = BIT_ROOT_PATH.'/'.$destUrl;
diff --git a/plugins/processor.magickwand.php b/plugins/processor.magickwand.php
index d05532c..4617c7a 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.8 2007/05/15 03:35:08 wjames5 Exp $
+ * $Header: /cvsroot/bitweaver/_bit_liberty/plugins/processor.magickwand.php,v 1.9 2007/06/23 17:29:57 squareing Exp $
*
* Image processor - extension: php-magickwand
* @package liberty
@@ -11,11 +11,10 @@
* liberty_magickwand_resize_image
*
* @param array $pFileHash
- * @param array $pFormat
* @access public
* @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
*/
-function liberty_magickwand_resize_image( &$pFileHash, $pFormat = NULL, $pThumbnail = false ) {
+function liberty_magickwand_resize_image( &$pFileHash, $pThumbnail = FALSE ) {
global $gBitSystem;
// static var here is crucial
static $rgbConverts = array();
@@ -48,14 +47,9 @@ function liberty_magickwand_resize_image( &$pFileHash, $pFormat = NULL, $pThumbn
MagickSetImageCompressionQuality( $magickWand, 85 );
$iwidth = round( MagickGetImageWidth( $magickWand ) );
$iheight = round( MagickGetImageHeight( $magickWand ) );
- $itype = MagickGetImageMimeType( $magickWand );
- if( $pThumbnail && $gBitSystem->isFeatureActive( 'liberty_png_thumbnails' )) {
- $format = 'PNG';
- } else {
- $format = 'JPG';
- }
- MagickSetImageFormat( $magickWand, $format );
+ // this does not seem to be needed. magickwand will work out what to do by using the destination file extension
+ //MagickSetImageFormat( $magickWand, $format );
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;
@@ -68,22 +62,31 @@ function liberty_magickwand_resize_image( &$pFileHash, $pFormat = NULL, $pThumbn
} elseif( !empty( $pFileHash['max_width'] ) ) {
$pFileHash['max_height'] = round( ($iheight / $iwidth) * $pFileHash['max_width'] );
}
+
// Make sure not to scale up
if( $pFileHash['max_width'] > $iwidth && $pFileHash['max_height'] > $iheight) {
$pFileHash['max_width'] = $iwidth;
$pFileHash['max_height'] = $iheight;
- }
+ }
- list($type, $mimeExt) = split( '/', strtolower( $itype ) );
- if ($gBitSystem->isFeatureActive('liberty_png_thumbnails')) {
- $targetType = 'png';
- $destExt = '.png';
+ $itype = MagickGetImageMimeType( $magickWand );
+
+ // 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( $itype ));
}
- else {
+
+ 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)) || !empty( $pFileHash['colorspace_conversion'] ) ) {
+
+ if( !empty( $pFileHash['max_width'] ) && !empty( $pFileHash['max_height'] ) && ( ($pFileHash['max_width'] < $iwidth || $pFileHash['max_height'] < $iheight ) || $mimeExt != $targetType ) || !empty( $pFileHash['colorspace_conversion'] ) ) {
$destUrl = $pFileHash['dest_path'].$pFileHash['dest_base_name'].$destExt;
$destFile = BIT_ROOT_PATH.'/'.$destUrl;
$pFileHash['name'] = $pFileHash['dest_base_name'].$destExt;