Notice (8): file_put_contents(): Write of 270 bytes failed with errno=28 No space left on device [CORE/src/Log/Engine/FileLog.php, line 140]

Notice: file_put_contents() [function.file-put-contents]: Write of 1108 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Notice (8): SplFileObject::fwrite() [<a href='https://secure.php.net/splfileobject.fwrite'>splfileobject.fwrite</a>]: Write of 5131 bytes failed with errno=28 No space left on device [CORE/src/Cache/Engine/FileEngine.php, line 141]

Notice: file_put_contents() [function.file-put-contents]: Write of 3151 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Notice (8): unserialize() [<a href='https://secure.php.net/function.unserialize'>function.unserialize</a>]: Error at offset 20444 of 20469 bytes [APP/Controller/NewsController.php, line 5571]

Notice: file_put_contents() [function.file-put-contents]: Write of 2759 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Notice (8): SplFileObject::fwrite() [<a href='https://secure.php.net/splfileobject.fwrite'>splfileobject.fwrite</a>]: Write of 4521 bytes failed with errno=28 No space left on device [CORE/src/Cache/Engine/FileEngine.php, line 141]

Notice: file_put_contents() [function.file-put-contents]: Write of 2791 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Warning (512): long cache was unable to write '5e642f9f4b8117a72101acf38351311f' to Cake\Cache\Engine\FileEngine cache [CORE/src/Cache/Cache.php, line 275]

Notice: file_put_contents() [function.file-put-contents]: Write of 2585 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Warning (2): Undefined array key "nsort" [APP/Controller/NewsController.php, line 3613]

Notice: file_put_contents() [function.file-put-contents]: Write of 2073 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Warning (2): Trying to access array offset on value of type null [APP/Controller/NewsController.php, line 3613]

Notice: file_put_contents() [function.file-put-contents]: Write of 2097 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Warning (2): Undefined array key "nsort" [APP/Controller/NewsController.php, line 3613]

Notice: file_put_contents() [function.file-put-contents]: Write of 2073 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Warning (2): Trying to access array offset on value of type null [APP/Controller/NewsController.php, line 3613]

Notice: file_put_contents() [function.file-put-contents]: Write of 2097 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Notice (8): SplFileObject::fwrite() [<a href='https://secure.php.net/splfileobject.fwrite'>splfileobject.fwrite</a>]: Write of 110 bytes failed with errno=28 No space left on device [CORE/src/Cache/Engine/FileEngine.php, line 141]

Notice: file_put_contents() [function.file-put-contents]: Write of 2790 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Warning (512): long cache was unable to write '2c6b1d5e2db0e076594dc34c6fe47a1a' to Cake\Cache\Engine\FileEngine cache [CORE/src/Cache/Cache.php, line 275]

Notice: file_put_contents() [function.file-put-contents]: Write of 2585 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Notice (8): SplFileObject::fwrite() [<a href='https://secure.php.net/splfileobject.fwrite'>splfileobject.fwrite</a>]: Write of 105 bytes failed with errno=28 No space left on device [CORE/src/Cache/Engine/FileEngine.php, line 141]

Notice: file_put_contents() [function.file-put-contents]: Write of 2790 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Warning (512): long cache was unable to write '166b5665adf7cea715cf44aebec38bb7' to Cake\Cache\Engine\FileEngine cache [CORE/src/Cache/Cache.php, line 275]

Notice: file_put_contents() [function.file-put-contents]: Write of 2585 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
php按百分比生成缩略图的代码示例 - 站长搜索
首页 > 资讯列表 > 编程/数据库 >>

php按百分比生成缩略图的代码示例

Warning (2): Undefined array key "nsort" [ROOT/plugins/Kuhuang/templates/Websites/view.php, line 430]
Notice: file_put_contents() [function.file-put-contents]: Write of 2421 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Warning (2): Trying to access array offset on value of type null [ROOT/plugins/Kuhuang/templates/Websites/view.php, line 430]

Notice: file_put_contents() [function.file-put-contents]: Write of 2445 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
">
Warning (2): Undefined array key "nsort" [ROOT/plugins/Kuhuang/templates/Websites/view.php, line 430]

Notice: file_put_contents() [function.file-put-contents]: Write of 2421 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Warning (2): Trying to access array offset on value of type null [ROOT/plugins/Kuhuang/templates/Websites/view.php, line 430]

Notice: file_put_contents() [function.file-put-contents]: Write of 2445 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
2014-12-02 01:20:05 转载来源: 网络整理/侵权必删

本文是一个php按百分比生成缩略图(等比例缩放)的代码示例,感兴趣的同学参考下。 最近的一个网站项目中上传图片需要生成缩略图,以减小列表页的大小,减缓服务器压力

本文是一个php百分比生成略图(等比例缩放)的代码示例,感兴趣的同学参考下。

最近的一个网站项目中上传图片需要生成缩略图,以减小列表页的大小,减缓服务器压力。一向崇尚简洁明了和实用的我,看到网上搜到的一个个长长的php缩略图类的时候,感到非常痛苦。我承认他们写的功能是强大一些,但是我不需要这么复杂的功能

于是翻了一下手册,弄懂几个函数后自己写了一个简单的php生成缩略图的程序。没有用类,我觉得一个函数就能搞定,而且对于新手来说更容易去理解,从而可以帮助到更多的人。

支持按比分比缩略,支持按指定的长宽缩略,默认按百分比。程序中注释已经很详细了,如有问题可在下面留言,欢迎与我交流。

源码如下:


<?php

 /*
  * param ori_img 原图像的名称和路径
  * param new_img 生成图像的名称
  * param percent 表示按照原图的百分比进行缩略,此项为空时默认按50%
  * param width 指定缩略后的宽度
  * param height 指定缩略后的高度
  *
  * 注:当 percent width height 都传入值的时候,且percent>0时,优先按照百分比进行缩略
  * by:http://www.jb51.net 更多源码与你分享
  * 温馨提示:使用此功能要在php.ini中开启 gd2
  *
  **/

 function makeThumb($ori_img, $new_img, $percent=50, $width=0, $height=0){

  $original = getimagesize($ori_img); //得到图片的信息,可以print_r($original)发现它就是一个数组
  //$original[2]是图片类型,其中1表示gif、2表示jpg、3表示png
  switch($original[2]){
   case 1 : $s_original = imagecreatefromgif($ori_img);
    break;
   case 2 : $s_original = imagecreatefromjpeg($ori_img);
    break;
   case 3 : $s_original = imagecreatefrompng($ori_img);
    break;
  }

  if($percent > 0){
   $width = $original[0] * $percent / 100;
   $width = ($width > 0) ? $width : 1;
   $height = $original[1] * $percent / 100;
   $height = ($height > 0) ? $height : 1;
  }

  //创建一个真彩的画布
  $canvas = imagecreatetruecolor($width,$height);
  imagecopyresized($canvas, $s_original, 0, 0, 0, 0, $width, $height, $original[0], $original[1]);
  //header("Content-type:image/jpeg");
  //imagejpeg($canvas); //向浏览器输出图片
  $loop = imagejpeg($canvas, $new_img); //生成新的图片
  if($loop){
   echo "OK!<br/>";
  }
 }

 makeThumb("bhsj.jpg","suolue1.jpg",15,0,0); //生成原图15%的缩略图
 makeThumb("bhsj.jpg","suolue2.jpg",0,200,120); //生成宽为100px,高为60px的缩略图
 makeThumb("bhsj.jpg","suolue3.jpg",15,200,120); //生成原图15%的缩略图(参数都填时,百分率优先级大)

?>

标签: php 百分比 生成 略图 代码 示例


声明:本文内容来源自网络,文字、图片等素材版权属于原作者,平台转载素材出于传递更多信息,文章内容仅供参考与学习,切勿作为商业目的使用。如果侵害了您的合法权益,请您及时与我们联系,我们会在第一时间进行处理!我们尊重版权,也致力于保护版权,站搜网感谢您的分享!

站长搜索

http://www.adminso.com

Copyright @ 2007~2024 All Rights Reserved.

Powered By 站长搜索

打开手机扫描上面的二维码打开手机版


使用手机软件扫描微信二维码

关注我们可获取更多热点资讯

站长搜索目录系统技术支持