Crop command is working well using negative offset parameters but transparent areas are trimming.
How can i keep transparent areas outside of canvas on crop?
Crop Image Using Outside of the Image
Re: Crop Image Using Outside of the Image
You need to:
Specify your IM version
Command you are using
Link to an image for testing
Specify your IM version
Command you are using
Link to an image for testing
Re: Crop Image Using Outside of the Image
Code: Select all
convert rose: -crop 70x45+0-10 crop.png
canvas size have to 70x45 with 10 pixels transparent area top of the canvas.
result:
10 pixel transparent area is trimmed and final canvas size is 70x35
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Crop Image Using Outside of the Image
"-crop" won't give you pixels that are outside the image. IM calls these "virtual pixel", as opposed to "authentic pixels" that are those inside the image. You can get virtual pixels with a viewport and a null "-distort", but if you want transparency, that is overkill.
If you simply want to append 10 rows to the top:
And you can crop that, if you want:
If you simply want to append 10 rows to the top:
Code: Select all
convert -size 1x10 xc:None rose: -background None -append out.png
Code: Select all
convert -size 1x10 xc:None rose: -background None -append -crop 70x35+0+0 +repage out.png
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Crop Image Using Outside of the Image
try this
Make the height 10 pixels more than the input and use the yoffset of -10. Set the background color to whatever you want.
Code: Select all
convert rose: -background none -gravity north -extent 70x55+0-10 crop.png
Re: Crop Image Using Outside of the Image
Thank you all.
My real reason is cropping image using PHP Imagick.
I just augmented some cropping strategies to use in PHP Imagick. I have to use -extent method to fit crop origin to 0,0.
Following code made my request.
My real reason is cropping image using PHP Imagick.
I just augmented some cropping strategies to use in PHP Imagick. I have to use -extent method to fit crop origin to 0,0.
Following code made my request.
Code: Select all
<?php
$imagick = new \Imagick();
$imagick->setBackgroundColor('white');
$imagick->readImage('in.png');
$width = $imagick->getImageWidth();
$height = $imagick->getImageHeight();
$width -= min(0, $width - ($crop['width'] + $crop['x']));
$width -= min(0, $crop['x']);
$height -= min(0, $height - ($crop['height'] + $crop['y']));
$height -= min(0, $crop['y']);
$imagick->extentImage($width, $height, $crop['x'], $crop['y']);
$imagick->cropImage($crop['width'], $crop['height'], 0, 0);
$imagick->setImagePage($crop['width'], $crop['height'], 0, 0);
$imagick->writeImage('out.png');
?>