imagejpeg php 300dpi,PHP: imagejpeg - Manual

function create_thumbnail( $source_file, $destination_file, $max_dimension)

{

list($img_width,$img_height) = getimagesize($source_file); // Get the original dimentions

$aspect_ratio = $img_width / $img_height;

if ( ($img_width > $max_dimension) || ($img_height > $max_dimension) ) // If either dimension is too big...

{

if ( $img_width > $img_height ) // For wide images...

{

$new_width = $max_dimension;

$new_height = $new_width / $aspect_ratio;

}

elseif ( $img_width < $img_height ) // For tall images...

{

$new_height = $max_dimension;

$new_width = $new_height * $aspect_ratio;

}

elseif ( $img_width == $img_height ) // For square images...

{

$new_width = $max_dimension;

$new_height = $max_dimension;

}

else { echo "Error reading image size."; return FALSE; }

}

else { $new_width = $img_width; $new_height = $img_height; } // If it's already smaller, don't change the size.

// Make sure these are integers.

$new_width = intval($new_width);

$new_height = intval($new_height);

$thumbnail = imagecreatetruecolor($new_width,$new_height); // Creates a new image in memory.

// The following block retrieves the source file.  It assumes the filename extensions match the file's format.

if ( strpos($source_file,".gif") ) { $img_source = imagecreatefromgif($source_file); }

if ( (strpos($source_file,".jpg")) || (strpos($source_file,".jpeg")) )

{ $img_source = imagecreatefromjpeg($source_file); }

if ( strpos($source_file,".bmp") ) { $img_source = imagecreatefromwbmp($source_file); }

if ( strpos($source_file,".png") ) { $img_source = imagecreatefrompng($source_file); }

// Here we resample and create the new jpeg.

imagecopyresampled($thumbnail, $img_source, 0, 0, 0, 0, $new_width, $new_height, $img_width, $img_height);

imagejpeg( $thumbnail, $destination_file, 100 );

// Finally, we destroy the two images in memory.

imagedestroy($img_source);

imagedestroy($thumbnail);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值