Reputation: 4193
I want to be able to trim images, many of which are very long vertically...anywhere from 2000 to 4000px, always at 800. So only getting the top part of the image. I then want to output this to a page/report with PHP, without storring the resultant trimmed image.
Is $imagepng->trim the best way to do this?
Upvotes: 0
Views: 128
Reputation: 6331
GD is what imagepng uses and it's the most widely-supported way of doing image manipulation in PHP, so it's a pretty safe bet, especially if you are looking to deploy your code on servers you don't control.
An alternative would be to look at ImageMagick, though I find GD is a little faster in most cases.
Upvotes: 0
Reputation: 321698
You'd do something like this:
$srcName = 'source.png';
$info = getimageinfo($srcName);
$src = imagecreatefrompng($srcName);
// Create a new image up to 800px tall
$dest = imagecreate($info[0], min($info[1], 800));
imagecopy($dest, $src, 0, 0, 0, 0, $info[0], min($info[1], 800));
// Output
header('Content-type: image/png');
imagepng($dest);
Upvotes: 1