Forum Moderators: coopster
code:--------------------------------------------------------------------------------
<?php
function RatioResizeImg($src_file, $dest_file, $gid) {
list($dbconn) = pnDBGetConn();
$pntable = pnDBGetTables();
$column = &$pntable['meg_categories_column'];
$query = "SELECT $column[thumbwidth] from $pntable[meg_categories] WHERE gallid=$gid";
$result = $dbconn->Execute($query);
list($newWidth) = $result->fields;
list($newHeight) = $result->fields;
switch(megConfigGetVar('imageSoftware')) {
case 'GD': return RatioResizeImgGD($src_file, $dest_file, $newWidth); break;
case 'ImageMagick': return RatioResizeImgImageMagick($src_file, $dest_file, $newWidth); break;
case 'none': return $src_file; break;
case 'browser': return 'browser'; break;
case 'NetPBM': return RatioResizeImgNetPBM($src_file, $dest_file, $newWidth, $newHeight); break;
default: return $src_file; break;
}
}
function RatioResizeImgNetPBM($src_file, $dest_file, $newWidth, $newHeight) {
/* Define where to find the various external binaries we need */
$netpbm = megConfigGetVar('netpbmPath'); /* default: home/www/pcmodeler/netpbm */
$djpeg =$netpbm."/djpeg"; /* decompresses a jpeg to ppm */
$cjpeg =$netpbm."/cjpeg"; /* compreses a ppm to jpeg format */
$pnmscale = $netpbm."/pnmscale"; /* scales a ppm image */
$pnmscale = $netpbm."/pnmscale"; /* scales a ppm image */
$jpgtopnm = $netpbm."/jpegtopnm"; /* convert a jpg to ppm */
$giftopnm = $netpbm."/giftopnm"; /* convert a gif to ppm */
$pngtopnm = $netpbm."/pngtopnm"; /* convert a png to ppm */
$ppmtojpg = $netpbm."/ppmtojpeg"; /* convert a ppm to jpg */
$ppmtogif = $netpbm."/ppmtogif"; /* convert a ppm to gif */
$ppmquant = $netpbm."/ppmquant"; /* colour quantize a ppm */
/* $imginfo = @getimagesize($src_file);
if ($galleryvar['imageSoftwarePath'] == '')
$cmd = $galleryvar['imageSoftwarePath']."/";
else
$cmd = "";
*/
if(!file_exists($dest_file)) {
if(ereg("\.gif$",$src_file)) { /* Look for .gif extension */
exec("$giftopnm $src_file ¦ $pnmscale -width $newWidth ".
"¦ $ppmquant 256 ¦ $ppmtogif -interlace > \"$dest_file\"");
} elseif(ereg("\.jpe?g",$src_file)) { /* Look for .jpg or .jpeg */
exec("$jpgtopnm $src_file ¦ $pnmscale -xysize $newWidth $newHeight".
"¦ $ppmtojpg > \"$dest_file\"");
} elseif(ereg("\.JPE?G",$src_file)) { /* Look for .JPG or .JPEG */
exec("$jpgtopnm $src_file ¦ $pnmscale -xysize $newWidth $newHeight".".
"¦ $ppmtojpg > \"$dest_file\"");
} elseif(ereg("\.png",$src_file)) { /* Look for .png */
exec("$pngtopnm $src_file ¦ $pnmscale -xysize $newWidth $newHeight".¦ ".
"¦ $ppmquant 256 ¦ $pngtopnm > \"$dest_file\"");
} else { /* not a GIF, PNG or JPG file */
return("");
}
}
return $dest_file;
}
?>
--------------------------------------------------------------------------------
So far, I can't get it to modify the width, so that portrait images are no larger than the variable. What am I missing?
I assume these three lines are the true issue (as well as the uppercase jpeg line)? I don't use netpbm so I don't really know the structure of the calls. Did you add just newHeight or were both newWidth and newHeight added to these calls?