在GD库中调整大小后裁剪图像 [英] crop an image after resizing in GD library

查看:86
本文介绍了在GD库中调整大小后裁剪图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要先按比例调整图像的大小(宽度是重要尺寸),然后裁剪以裁切任何多余的高度,然后将新版本存储在目录中.

I need to first resize an image proportionally (the width is the important dimension) and then crop afterwards to chop of any excess height and then store the new version in a directory.

我已经成功地进行了大小调整,最终得到的图像是目录中正确宽度的图像.在这里,我需要剪掉多余的高度.但是我无法解决需要做的事情.我是否需要以某种方式使用copyimageresampled.我想裁剪所有图像,使它们的高度为50px.

I've managed to do the resizing fine and I end up with images that are the correct width in my directory. Somehwere in here I need to crop the excess height off. But I can't work out where I need to do it. Do I need to use copyimageresampled somehow. I want to crop all images so they're 50px in height.

这是我到目前为止调整大小的内容:

Here's what I have so far fo the resizing:

$src = ImageCreateFromJpeg($upfile);
$dst = ImageCreateTrueColor($tn_width, $tn_height);
ImageCopyResized($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height);
ImageJpeg($dst, 'images/' . $_FILES['image']['name']);

推荐答案

这就是我所追求的.一个2阶段的过程.技巧是将图像调整为临时图像,然后裁剪它:

This is what I was after. A 2 stage process. The trick is to resize the image in to a temporary image and then crop it:

http://salman- w.blogspot.com/2009/04/crop-to-fit-image-using-aspphp.html

这篇关于在GD库中调整大小后裁剪图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆