php生成图片缩略图功能示例

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php生成图片缩略图功能示例脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

本文实例讲述了PHP生成图片缩略图功能分享给大家供大家参考,具体如下:

完整代码如下(为方便阅读,代码使用进行了格式化处理):

 $srcH * $dstW) {
    $fdstH = round($srcH * $dstW / $srcW);
    $dstY = floor(($dstH - $fdstH) / 2);
    $fdstW = $dstW;
  } else {
    $fdstW = round($srcW * $dstH / $srcH);
    $dstX = floor(($dstW - $fdstW) / 2);
    $fdstH = $dstH;
  }
  $ni = ImageCreateTrueColor($dstW,$dstH);
  $dstX = ($dstX < 0)="" 0="" :="" $dstx;="" $dsty="($dstX">< 0)="" 0="" :="" $dsty;="" $dstx="($dstX"> ($dstW / 2)) ? floor($dstW / 2) : $dstX;
  $dstY = ($dstY > ($dstH / 2)) ? floor($dstH / s) : $dstY;
  $whITe = ImageColorAllocate($ni,255,255);
  $black = ImageColorAllocate($ni,0);
  imagefilledrectangle($ni,$white); // 填充背景色
  ImageCopyResized($ni,$im,$dstX,$dstY,$fdstW,$fdstH,$srcW,$srcH);
  if ($markwords != null) {
    $markwords = iconv("gb2312","UTF-8",$markwords);
    //转换文字编码
    ImageTTFText($ni,20,30,450,560,$black,"simhei.ttf",$markwords); //写入文字水印
    //参数依次为,文字大小|偏转度|横坐标|纵坐标|文字颜色|文字类型|文字内容

} elseif ($markimage != null) {
$wimage_data = GetImageSize($markimage);
switch ($wimage_data[2]) {
case 1:
$wimage = @imagecreatefromGIF($markimage);
break;
case 2:
$wimage = @ImageCreateFromJPEG($markimage);
break;
case 3:
$wimage = @ImageCreateFromPNG($markimage);
break;
}
imagecopy($ni,$wimage,500,88,31); //写入图片水印,水印图片大小默认为88*31
imagedestroy($wimage);
}
ImageJpeg($ni,$rate);
ImageJpeg($ni,$srCFile,$rate);
imagedestroy($im);
imagedestroy($ni);
}
?>

脚本宝典总结

以上是脚本宝典为你收集整理的php生成图片缩略图功能示例全部内容,希望文章能够帮你解决php生成图片缩略图功能示例所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。