php生成图片缩略图的方法

yipeiwu_com6年前PHP代码库

本文实例讲述了php生成图片缩略图的方法。分享给大家供大家参考。具体如下:

这里需要用到GD2 library

function make_thumb($src,$dest,$desired_width)
{
 
  /* read the source image */
  $source_image = imagecreatefromjpeg($src);
  $width = imagesx($source_image);
  $height = imagesy($source_image);
  /* find the "desired height" of this thumbnail, relative to the desired width */
  $desired_height = floor($height*($desired_width/$width));
  /* create a new, "virtual" image */
  $virtual_image = imagecreatetruecolor($desired_width,$desired_height);
  /* copy source image at a resized size */
  imagecopyresized($virtual_image,$source_image,0,0,0,0,$desired_width,$desired_height,$width,$height);
  /* create the physical thumbnail image to its destination */
  imagejpeg($virtual_image,$dest, 83);
}

希望本文所述对大家的php程序设计有所帮助。

相关文章

PHP实现的数组和XML文件相互转换功能示例

本文实例讲述了PHP实现的数组和XML文件相互转换功能。分享给大家供大家参考,具体如下: 最近搞微信支付,微信服务器返回的都是XML文件,所以需要转换成数组,才会便于操作,好了话不多说,...

php7新特性的理解和比较总结

php7新特性的理解和比较总结

1. null合并运算符(??) 语法: 如果变量存在且值不为NULL,它就会返回自身的值,否则返回它的第二个操作数. //php7以前 if判断 if(emp...

php实现数组纵向转横向并过滤重复值的方法分析

本文实例讲述了php实现数组纵向转横向并过滤重复值的方法。分享给大家供大家参考,具体如下: 一、问题 有数组: array( 6=>array(5=>'黑xx', 4...

10个实用的PHP代码片段

关键词高亮 复制代码 代码如下: function highlight($sString, $aWords) { if (!is_array ($aWords) || empty ($a...

微信 开发生成带参数的二维码的实例

微信开发生成带参数的二维码的讲解 在微信公众号平台开发者那里,在“账号管理”那里,有一项功能是“生成带参数的二维码”,通过这儿生成的二维码,只要通过微信扫一扫之后,会把事件自动推送到微...