Hi there! XnView is a great masterpiece! I Use it with pleasure.
Will explain my Problem briefly:
I need to automatically rotate image on X degrees, so that black areas are automatically cropped.
I used these commands, neither of them helped so far.
nconvert.exe -rotate 10 -rotate_flag smooth -autocrop 0 0 0 0 1.jpg
nconvert.exe -rotate 10 -rotate_flag smooth -autocrop 255 0 0 0 1.jpg
nconvert.exe -autocrop 0 0 0 0 1.jpg // this is for already rotated image
I also tried to auto crop from XnView UI menu. It doesn't crop black area after rotation.
The only way it works - it is manually launch custom rotation with auto crop option from xnview image menu.
Is auto crop option (-rotate_flag auto crop) for custom rotation (-rotate degree) implemented in the command line for NConvert?
Please advice how to automatically crop rotated images
NConvert AutoCrop option after Rotate doesn't work
Moderators: helmut, XnTriq, xnview
-
- Posts: 6
- Joined: Thu Jun 26, 2014 7:06 am
NConvert AutoCrop option after Rotate doesn't work
Last edited by tigran on Thu Jun 26, 2014 8:36 am, edited 2 times in total.
-
- XnThusiast
- Posts: 4349
- Joined: Sun Apr 29, 2012 9:45 am
- Location: Cheltenham, U.K.
Re: NConvert AutoCrop option after Rotate don't work
Could you upload an example image that you need to process?
-
- Posts: 6
- Joined: Thu Jun 26, 2014 7:06 am
Re: NConvert AutoCrop option after Rotate don't work
here you go, this is just as a sample to explain the problem of black borders after rotation that are not cropped
You do not have the required permissions to view the files attached to this post.
-
- XnThusiast
- Posts: 4349
- Joined: Sun Apr 29, 2012 9:45 am
- Location: Cheltenham, U.K.
Re: NConvert AutoCrop option after Rotate doesn't work
In general NConvert implements commands available in XnView, so developing a useable NConvert script is often conveniently done by first finding the XnView operations required to perform the action(s) required, and then debugging the command line script.
1. Image > Rotate > Custom... : Background colour = Black (0,0,0) , angle = -2 degrees
2. Image > Automatic crop... : Background colour = Black (0,0,0) , Tolerance = 100 (For example)
Which produces the following image:
Is this about the result you need?
Are the black edge areas in your original image that you wish to remove due to a previous rotation? If so, selecting a background colour for the rotation that more closely matches the colours in the image would reduce the unwanted effect, although likely not enough to be useful in general.
I'm not entirely clear about what you're trying to do, or whether, if a custom rotation is required in XnView, it is actually possible using NConvert...
Edit:
Is the image you uploaded the original image you started with, or the image after you made a custom rotation?
tigran wrote:The only way it works - it is manually launch custom rotation with auto crop option from xnview image menu.
I think I've obtained about the XnView result that you need with the following operations:I also tried to auto crop from XnView UI menu. It doesn't crop black area after rotation.
1. Image > Rotate > Custom... : Background colour = Black (0,0,0) , angle = -2 degrees
2. Image > Automatic crop... : Background colour = Black (0,0,0) , Tolerance = 100 (For example)
Which produces the following image:
Is this about the result you need?
Are the black edge areas in your original image that you wish to remove due to a previous rotation? If so, selecting a background colour for the rotation that more closely matches the colours in the image would reduce the unwanted effect, although likely not enough to be useful in general.
I'm not entirely clear about what you're trying to do, or whether, if a custom rotation is required in XnView, it is actually possible using NConvert...
Edit:
Is the image you uploaded the original image you started with, or the image after you made a custom rotation?
You do not have the required permissions to view the files attached to this post.
-
- Posts: 6
- Joined: Thu Jun 26, 2014 7:06 am
Re: NConvert AutoCrop option after Rotate doesn't work
Thanks for your reply, cday!
Your above quote is the answer.
It was altered image.
My Goal: original normal image -> rotate on some angle -> remove black triangle areas (crop). this should be done automatically.
Manually it can be done as I said in my 1st msg: open xnview -> image -> rotate-> custom -> set angle and turn on 'auto crop' option
Is the image you uploaded the original image you started with, or the image after you made a custom rotation?
Your above quote is the answer.
It was altered image.
My Goal: original normal image -> rotate on some angle -> remove black triangle areas (crop). this should be done automatically.
Manually it can be done as I said in my 1st msg: open xnview -> image -> rotate-> custom -> set angle and turn on 'auto crop' option
-
- Posts: 6
- Joined: Thu Jun 26, 2014 7:06 am
Re: NConvert AutoCrop option after Rotate doesn't work
The problem in NConvert and XnView batch procesing is :
NConvert:
NConvert:
- doesn't have auto crop option as a flag for -rotate_flag
- separate -autocrop option, doesn't work for an image that I posted above (doesn't remove triangle black areas appeared after rotation)
- doesn't have 'auto crop' option for rotation in batch proceesing mode
- manual autocrop option in Image menu, doesn't work for an image that I posted above (doesn't remove triangle black areas appeared after rotation)
-
- XnThusiast
- Posts: 4349
- Joined: Sun Apr 29, 2012 9:45 am
- Location: Cheltenham, U.K.
Re: NConvert AutoCrop option after Rotate doesn't work
Thanks, could you upload the original image as that may make the overall problem clearer: sometimes a slightly different approach can be the best overall solution.tigran wrote:It was altered image.
If a custom rotation is necessary for each image, clearly that can't be automated in NConvert, so it would only be possible to use the same fixed operations from that point on.
XnView also now has an auto-deskew option, if that would be useful in principle, but it doesn't process colour images...
-
- Posts: 6
- Joined: Thu Jun 26, 2014 7:06 am
Re: NConvert AutoCrop option after Rotate doesn't work
That is what I'm trying to automate:
You do not have the required permissions to view the files attached to this post.
-
- XnThusiast
- Posts: 4349
- Joined: Sun Apr 29, 2012 9:45 am
- Location: Cheltenham, U.K.
Re: NConvert AutoCrop option after Rotate doesn't work
That's an excellent illustration that makes the problem clearer.
The first operation is a small rotation: do you want to automate that, using a fixed rotation angle, or to do a custom rotation for each image and then use NConvert for only the second operation?
The second operation could only be done using autocrop if the image is straightened first, as in the image I posted: autocrop crops each edge of the overall image in to the start of the image itself, and so produces a rectangular crop as if you had made a manual selection. You have probably seen that, but that is the way autocrop works...
The second operation as shown could be done as a simple crop using NConvert, but only if the same pixel settings could be used for each image.
A better solution would probably be to use -canvas , with the position 'pos' set to center : if the 'percent' option is used it should be possible to process images with different pixel dimensions using the same resize proportions.

The first operation is a small rotation: do you want to automate that, using a fixed rotation angle, or to do a custom rotation for each image and then use NConvert for only the second operation?
The second operation could only be done using autocrop if the image is straightened first, as in the image I posted: autocrop crops each edge of the overall image in to the start of the image itself, and so produces a rectangular crop as if you had made a manual selection. You have probably seen that, but that is the way autocrop works...
The second operation as shown could be done as a simple crop using NConvert, but only if the same pixel settings could be used for each image.
A better solution would probably be to use -canvas , with the position 'pos' set to center : if the 'percent' option is used it should be possible to process images with different pixel dimensions using the same resize proportions.
-
- Posts: 6
- Joined: Thu Jun 26, 2014 7:06 am
Re: NConvert AutoCrop option after Rotate doesn't work
cday, you made my day, man 
yep, I looped on the non-existent feature in batch mode for nconvert/xnview.
But it actually can be bypassed with canvas resizing nconvert option:
nconvert.exe -rotate 2 -canvas 90% 90% center Image.jpg
You should play with percentage that best matches chosen rotation angle.
Hope it will help somebody.

yep, I looped on the non-existent feature in batch mode for nconvert/xnview.
But it actually can be bypassed with canvas resizing nconvert option:
nconvert.exe -rotate 2 -canvas 90% 90% center Image.jpg
You should play with percentage that best matches chosen rotation angle.
Hope it will help somebody.