裁剪图片PHP代码

WBOY
发布: 2016-07-25 08:46:15
原创
982 人浏览过

下面的例子裁切图片的左上角的100x100的部分。可以通过修改$src_x,$src_y,$src_w,$src_h的值来修改裁剪的范围。

  1. $filename= "test.jpg";
  2. list($w, $h, $type, $attr) = getimagesize($filename);
  3. $src_im = imagecreatefromjpeg($filename);
  4. $src_x = '0'; // begin x
  5. $src_y = '0'; // begin y
  6. $src_w = '100'; // width
  7. $src_h = '100'; // height
  8. $dst_x = '0'; // destination x
  9. $dst_y = '0'; // destination y
  10. $dst_im = imagecreatetruecolor($src_w, $src_h);
  11. $white = imagecolorallocate($dst_im, 255, 255, 255);
  12. imagefill($dst_im, 0, 0, $white);
  13. imagecopy($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h);
  14. header("Content-type: image/png");
  15. imagepng($dst_im);
  16. imagedestroy($dst_im);
  17. ?>
复制代码

PHP


相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!