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中mt_rand()随机数的安全

前言 在前段时间挖了不少跟mt_rand()相关的安全漏洞,基本上都是错误理解随机数用法导致的。这里又要提一下php官网manual的一个坑,看下关于mt_rand()的介绍:中文版^c...

php数据访问之增删改查操作

php数据访问之增删改查操作

增删改查操作小练习,大家练练手吧 一、查看新闻页面-----主页面 <html> <head> <meta http-equiv="Content...

php Notice: Undefined index 错误提示解决方法

第一种方法:如果不影响程序的正常执行,可以采用屏蔽的方法可以在代码的第一行 加上 error_reporting(E_ALL ^ E_NOTICE); 关闭掉 NOTICE错误的警告第二...

ThinkPHP5 验证器的具体使用

ThinkPHP5 验证器的具体使用

前言: 我们在做API开发的时候,我们会接受客户端传来的参数,大家都知道这个参数是不可信的,我们后端开发人员必须对这个参数进行验证。我在之前的开发中只是知道tp5的验证器,并不知道他的用...

PHP简单预防sql注入的方法

本文实例讲述了PHP简单预防sql注入的方法。分享给大家供大家参考,具体如下: 出现sql注入一般都是因为语法不规范不严谨造成的,问题出现在sql语句上,而起决定性的是quote(')。...