Source for file processor.gd.php
Documentation is available at processor.gd.php
* Image processor - extension: php-gd
* @subpackage plugins_processor
* @author spider <spider@steelsun.com>
* liberty_gd_resize_image
* @param array $pFileHash
* @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
list ($iwidth, $iheight, $itype, $iattr) = @getimagesize( $pFileHash['source_file'] );
if( ( empty( $pFileHash['max_width'] ) || empty( $pFileHash['max_height'] ) ) || ( $iwidth <= $pFileHash['max_width'] && $iheight <= $pFileHash['max_height'] && ( $ext == 'gif' || $ext == 'png' || $ext == 'jpg' || $ext == 'jpeg' ) ) ) {
// Keep the same dimensions as input file
$pFileHash['max_width'] = $iwidth;
$pFileHash['max_height'] = $iheight;
} elseif( $iheight && (($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;
// we need to scale and/or reformat
$fp = fopen( $pFileHash['source_file'], "rb" );
if( !empty( $img ) && $size_x && $size_y ) {
if( $size_x > $size_y && !empty( $pFileHash['max_width'] ) ) {
$tscale = ( (int) $size_x / $pFileHash['max_width'] );
} elseif( !empty( $pFileHash['max_height'] ) ) {
$tscale = ( (int) $size_y / $pFileHash['max_height'] );
$tw = ( (int) ( $size_x / $tscale ));
$ty = ( (int) ( $size_y / $tscale ));
//$imagegallib->ImageCopyResampleBicubic($t, $img, 0, 0, 0, 0, $tw, $ty, $size_x, $size_y);
// override $mimeExt if we have a custom setting for it
$mimeExt = $gBitSystem->getConfig( 'liberty_thumbnail_format' );
// make sure we have image_type_to_extension available
include_once( UTIL_PKG_PATH. 'PHP_Compat/Compat/Function/image_type_to_mime_type.php' );
if( $mimeExt = preg_replace( "!^(x-)?(jpeg|png|gif)$!", "$2", $mimeExt )) {
if( !$mimeExt || $mimeExt == 'jpeg' ) {
if( !empty( $pFileHash['dest_file'] ) ) {
$destFile = $pFileHash['dest_file'];
$destFile = STORAGE_PKG_PATH. $pFileHash['dest_branch']. $pFileHash['dest_base_name']. $destExt;
// png alpha stuff - needs more testing - spider
// imagecolorallocatealpha ( $t, 0, 0, 0, 127 );
// $ImgWhite = imagecolorallocate($t, 255, 255, 255);
// imagefill($t, 0, 0, $ImgWhite);
// imagecolortransparent($t, $ImgWhite);
// This must go immediately before default so default will be hit for PHP's without gif support
// 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 );
} elseif( $iwidth && $iheight ) {
* liberty_gd_rotate_image
* @param array $pFileHash
* @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
$pFileHash['error'] = "Rotate is not available on this webserver.";
} elseif( empty( $pFileHash['degrees'] ) || !is_numeric( $pFileHash['degrees'] ) ) {
$pFileHash['error'] = tra( 'Invalid rotation amount' );
// we need to scale and/or reformat
$fp = fopen( $pFileHash['source_file'], "rb" );
// image rotate degrees seems back ass words.
$rotateImg = imagerotate ( $img, (- 1 * $pFileHash['degrees']), 0 );
if( !empty( $rotateImg ) ) {
imagejpeg( $rotateImg, $pFileHash['source_file'] );
$pFileHash['error'] = "Image rotation failed.";
$pFileHash['error'] = "Image could not be opened for rotation.";
return( empty( $pFileHash['error'] ) );
* liberty_gd_can_thumbnail_image
* @param array $pMimeType
* @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
if( !empty( $pMimeType )) {
* @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
if( empty( $_SESSION['gd_version'] )) {
$_SESSION['gd_version'] = preg_replace( "!\D*([\d|\.]*)!", "$1", $gd['GD Version'] );
return $_SESSION['gd_version'];
return preg_replace( "!^(\d)+.*$!", "$1", $_SESSION['gd_version'] );
// nicked from http://at2.php.net/manual/en/function.gd-info.php
"FreeType Linkage" => "",
"GIF Create Support" => 0,
foreach(explode("\n", $info) as $line) {
if(strpos($line, "GD Version")!== false)
if(strpos($line, "FreeType Support")!== false)
if(strpos($line, "FreeType Linkage")!== false)
if(strpos($line, "T1Lib Support")!== false)
if(strpos($line, "GIF Read Support")!== false)
if(strpos($line, "GIF Create Support")!== false)
if(strpos($line, "GIF Support")!== false)
if(strpos($line, "JPG Support")!== false)
if(strpos($line, "PNG Support")!== false)
if(strpos($line, "WBMP Support")!== false)
if(strpos($line, "XBM Support")!== false)
if($gif_support=== "enabled") {
$array["GIF Read Support"] = 1;
$array["GIF Create Support"] = 1;
if($array["FreeType Support"]=== "enabled")
$array["FreeType Support"] = 1;
if($array["T1Lib Support"]=== "enabled")
$array["T1Lib Support"] = 1;
if($array["GIF Read Support"]=== "enabled")
$array["GIF Read Support"] = 1;
if($array["GIF Create Support"]=== "enabled")
$array["GIF Create Support"] = 1;
if($array["JPG Support"]=== "enabled")
$array["JPG Support"] = 1;
if($array["PNG Support"]=== "enabled")
$array["PNG Support"] = 1;
if($array["WBMP Support"]=== "enabled")
$array["WBMP Support"] = 1;
if($array["XBM Support"]=== "enabled")
$array["XBM Support"] = 1;
|