diff options
| -rw-r--r-- | LibertyAttachable.php | 19 | ||||
| -rw-r--r-- | plugins/processor.gd.php | 21 | ||||
| -rw-r--r-- | plugins/processor.imagick.php | 18 | ||||
| -rw-r--r-- | plugins/processor.magickwand.php | 23 | ||||
| -rw-r--r-- | plugins/storage.bitfile.php | 9 |
5 files changed, 69 insertions, 21 deletions
diff --git a/LibertyAttachable.php b/LibertyAttachable.php index 3313d01..d577a44 100644 --- a/LibertyAttachable.php +++ b/LibertyAttachable.php @@ -3,7 +3,7 @@ * Management of Liberty Content * * @package liberty - * @version $Header: /cvsroot/bitweaver/_bit_liberty/LibertyAttachable.php,v 1.59 2007/02/16 14:48:47 spiderr Exp $ + * @version $Header: /cvsroot/bitweaver/_bit_liberty/LibertyAttachable.php,v 1.60 2007/02/16 17:08:59 nickpalmer Exp $ * @author spider <spider@steelsun.com> */ // +----------------------------------------------------------------------+ @@ -811,6 +811,12 @@ function liberty_clear_thumbnails( &$pFileHash ) { if( file_exists( $fullPath ) ) { unlink( $fullPath ); } + // Also check for png version. + $fullPath = BIT_ROOT_PATH.$pFileHash['dest_path']."$size.png"; + if( file_exists( $fullPath ) ) { + unlink( $fullPath ); + } + } } @@ -862,14 +868,21 @@ function liberty_generate_thumbnails( &$pFileHash ) { $pFileHash['original_path'] = BIT_ROOT_PATH.$resizeFunc( $pFileHash ); } + if ($gBitSystem->isFeatureActive('liberty_png_thumbnails')) { + $ext = '.png'; + } + else { + $ext = '.jpg'; + } + foreach( $pFileHash['thumbnail_sizes'] as $thumbSize ) { if( isset( $gThumbSizes[$thumbSize] ) ) { // Icon thumb is 48x48 $pFileHash['dest_base_name'] = $thumbSize; - $pFileHash['name'] = $thumbSize.'.jpg'; + $pFileHash['name'] = $thumbSize.$ext; $pFileHash['max_width'] = $gThumbSizes[$thumbSize]['width']; $pFileHash['max_height'] = $gThumbSizes[$thumbSize]['height']; - $pFileHash['icon_thumb_path'] = BIT_ROOT_PATH.$resizeFunc( $pFileHash ); + $pFileHash['icon_thumb_path'] = BIT_ROOT_PATH.$resizeFunc( $pFileHash, NULL, true); } } } diff --git a/plugins/processor.gd.php b/plugins/processor.gd.php index dc2f7ef..9e24b51 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.1 2006/12/22 11:53:17 squareing Exp $ + * $Header: /cvsroot/bitweaver/_bit_liberty/plugins/processor.gd.php,v 1.2 2007/02/16 17:09:00 nickpalmer Exp $ * * Image processor - extension: php-gd * @package liberty @@ -15,7 +15,8 @@ * @access public * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure */ -function liberty_gd_resize_image( &$pFileHash, $pFormat = NULL ) { +function liberty_gd_resize_image( &$pFileHash, $pFormat = NULL, $pThumbnail = false ) { + global $gBitSystem; $ret = NULL; list($iwidth, $iheight, $itype, $iattr) = @getimagesize( $pFileHash['source_file'] ); list($type, $ext) = split( '/', strtolower( $pFileHash['type'] ) ); @@ -62,6 +63,8 @@ function liberty_gd_resize_image( &$pFileHash, $pFormat = NULL ) { // $ImgWhite = imagecolorallocate($t, 255, 255, 255); // imagefill($t, 0, 0, $ImgWhite); // imagecolortransparent($t, $ImgWhite); + imagesavealpha($t, true); + imagealphablending($t, false); imagecopyresampled($t, $img, 0, 0, 0, 0, $tw, $ty, $size_x, $size_y); } else { $t = imagecreate($tw, $ty); @@ -90,9 +93,17 @@ function liberty_gd_resize_image( &$pFileHash, $pFormat = NULL ) { break; } default: - $ext = '.jpg'; - $destFile = BIT_ROOT_PATH.'/'.$destUrl.$ext; - imagejpeg( $t, $destFile ); + 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; + imagejpeg( $t, $destFile ); + } + if(chmod($destFile, 0644)){ // does nothing, but fails elegantly } diff --git a/plugins/processor.imagick.php b/plugins/processor.imagick.php index bbe8d15..1c2884c 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.1 2006/12/22 11:53:17 squareing Exp $ + * $Header: /cvsroot/bitweaver/_bit_liberty/plugins/processor.imagick.php,v 1.2 2007/02/16 17:08:59 nickpalmer Exp $ * * Image processor - extension: php-imagick * @package liberty @@ -15,7 +15,8 @@ * @access public * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure */ -function liberty_imagick_resize_image( &$pFileHash, $pFormat = NULL ) { +function liberty_imagick_resize_image( &$pFileHash, $pFormat = NULL , $pThumbnail = false) { + global $gBitSystem; $pFileHash['error'] = NULL; $ret = NULL; if( !empty( $pFileHash['source_file'] ) && is_file( $pFileHash['source_file'] ) ) { @@ -38,9 +39,16 @@ function liberty_imagick_resize_image( &$pFileHash, $pFormat = NULL ) { } $itype = imagick_getmimetype( $iImg ); list($type, $mimeExt) = split( '/', strtolower( $itype ) ); - if( !empty( $pFileHash['max_width'] ) && !empty( $pFileHash['max_height'] ) && ( ($pFileHash['max_width'] < $iwidth || $pFileHash['max_height'] < $iheight ) || ($mimeExt != 'jpeg')) ) { - // We have to resize. *ALL* resizes are converted to jpeg - $destExt = '.jpg'; + 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)) ) { + // 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; $pFileHash['name'] = $pFileHash['dest_base_name'].$destExt; diff --git a/plugins/processor.magickwand.php b/plugins/processor.magickwand.php index 1657a85..e0a92b0 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.2 2007/02/14 02:59:14 spiderr Exp $ + * $Header: /cvsroot/bitweaver/_bit_liberty/plugins/processor.magickwand.php,v 1.3 2007/02/16 17:08:59 nickpalmer Exp $ * * Image processor - extension: php-magickwand * @package liberty @@ -15,7 +15,7 @@ * @access public * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure */ -function liberty_magickwand_resize_image( &$pFileHash, $pFormat = NULL ) { +function liberty_magickwand_resize_image( &$pFileHash, $pFormat = NULL, $pThumbnail = false ) { global $gBitSystem; // static var here is crucial static $rgbConverts = array(); @@ -65,7 +65,13 @@ function liberty_magickwand_resize_image( &$pFileHash, $pFormat = NULL ) { $iheight = round( MagickGetImageHeight( $magickWand ) ); $itype = MagickGetImageMimeType( $magickWand ); - MagickSetImageFormat( $magickWand, 'JPG' ); + if ($pThumbnail && $gBitSystem->isFeatureActive('liberty_png_thumbnails')) { + $format = 'PNG'; + } + else { + $format = 'JPG'; + } + 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; @@ -78,7 +84,6 @@ function liberty_magickwand_resize_image( &$pFileHash, $pFormat = NULL ) { } 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; @@ -86,9 +91,15 @@ function liberty_magickwand_resize_image( &$pFileHash, $pFormat = NULL ) { } list($type, $mimeExt) = split( '/', strtolower( $itype ) ); - if( !empty( $pFileHash['max_width'] ) && !empty( $pFileHash['max_height'] ) && ( ($pFileHash['max_width'] < $iwidth || $pFileHash['max_height'] < $iheight ) || ($mimeExt != 'jpeg')) || !empty( $pFileHash['colorspace_conversion'] ) ) { - // We have to resize. *ALL* resizes are converted to jpeg + if ($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)) || !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; diff --git a/plugins/storage.bitfile.php b/plugins/storage.bitfile.php index 6c9b419..ffb6b85 100644 --- a/plugins/storage.bitfile.php +++ b/plugins/storage.bitfile.php @@ -1,6 +1,6 @@ <?php /** - * @version $Revision: 1.18 $ + * @version $Revision: 1.19 $ * @package liberty * @subpackage plugins_storage */ @@ -71,7 +71,12 @@ function bit_files_load( $pRow ) { WHERE a.`foreign_id` = ? AND a.`content_id` = ?"; if( $ret = $gBitSystem->mDb->getRow($query, array( $pRow['foreign_id'], $pRow['content_id'] )) ) { $canThumbFunc = liberty_get_function( 'can_thumbnail' ); - if ( file_exists( BIT_ROOT_PATH.dirname( $ret['storage_path'] ).'/small.jpg' ) ) { + if ( file_exists( BIT_ROOT_PATH.dirname( $ret['storage_path'] ).'/small.png' ) ) { + $ret['thumbnail_url']['avatar'] = BIT_ROOT_URL.dirname( $ret['storage_path'] ).'/avatar.png'; + $ret['thumbnail_url']['small'] = BIT_ROOT_URL.dirname( $ret['storage_path'] ).'/small.png'; + $ret['thumbnail_url']['medium'] = BIT_ROOT_URL.dirname( $ret['storage_path'] ).'/medium.png'; + $ret['thumbnail_url']['large'] = BIT_ROOT_URL.dirname( $ret['storage_path'] ).'/large.png'; + } elseif ( file_exists( BIT_ROOT_PATH.dirname( $ret['storage_path'] ).'/small.jpg' ) ) { $ret['thumbnail_url']['avatar'] = BIT_ROOT_URL.dirname( $ret['storage_path'] ).'/avatar.jpg'; $ret['thumbnail_url']['small'] = BIT_ROOT_URL.dirname( $ret['storage_path'] ).'/small.jpg'; $ret['thumbnail_url']['medium'] = BIT_ROOT_URL.dirname( $ret['storage_path'] ).'/medium.jpg'; |
