Kangol
December 10, 2018, 7:39am
1
I want to crop an image and am using convert
convert mountain.png -crop 3000x4500 +repage -format png mountain--cr.png
The problem is that convert is creating 4 files
mountain--cr-0.png
mountain--cr-1.png
mountain--cr-2.png
mountain--cr-3.png
The first is what I need, the other look empty
Neo
December 10, 2018, 8:21am
2
Please provide and post full details of your operation system and version of your image utilities.
Thanks.
Kangol
December 10, 2018, 8:33am
3
I am using
ImageMagick 6.7.7-10 2014-08-28 Q16
My system is GNU Trisquel 7.0 with Gnome Version 3.8.4
Neo
December 10, 2018, 8:51am
4
Just for fun, have you tried to resize the image before you crop?
Ref:
Image Settings: -adjoin join images into a single multi-image file -affine matrix affine transform matrix -alpha option activate, deactivate, reset, or set the alpha channel -antialias remove pixel-aliasing -authenticate value dec
Kangol
December 10, 2018, 8:56am
5
Using the following command did not work, still getting the 4 files.
convert mountain.png -crop 3000x4500 +repage -format png -resize 3000x4500 mountain--cr.png
Neo
December 10, 2018, 9:02am
6
Maybe try resizing first, for fun....
convert mountain.png -resize 3000x4500 mountain-resize.png
convert mountain-resize.png -crop 3000x4500 mountain-resize-crop.png
Or something similar and simple, step-by-step?
Just to see what happens?
Kangol
December 10, 2018, 9:03am
7
I have an image with a big canvas, and the image falls within it. I am trying to crop to the size of the actual image.
apmcd47
December 10, 2018, 9:22am
8
Stupid question: What do you get if you type
identify mountain.png
Maybe the output of that will give a clue as to why you get four files from the convert command.
Andrew
bakunin
December 10, 2018, 9:24am
9
kangol:
The problem is that convert is creating 4 files
mountain--cr-0.png
mountain--cr-1.png
mountain--cr-2.png
mountain--cr-3.png
The first is what I need, the other look empty
OK, but what is the problem? Throw away the other 3 if you don't need them. Or do you want to autmate the process? If so, it would be nice to know your OS, your shell, ... you now the drill. Supposing you can use Korn shell and your system has the standard features how about this:
bakunin@host $ cat myconvert.sh
#! /bin/ksh
typeset fIn="$1"
typeset chExt=".png"
fIn="${fIn#${chExt}}"
if ! [ -f "${fIn}.${chExt}" ; then
print -u2 "Cannot find file ${fIn}.${chExt}."
exit 1
fi
if convert "$fIn.$chExt" -crop 3000x4500 +repage -format png "${fIn}--cr.${chExt}" ; then
rm "${fIn}-cr-1.${chExt}"
rm "${fIn}-cr-2.${chExt}"
rm "${fIn}-cr-3.${chExt}"
mv "${fIn}-cr-0.${chExt}" "${fIn}-cr.${chExt}"
exit 0
fi
exit $?
I hope this helps.
Kangol
December 10, 2018, 10:26am
10
I prefer not to resize the image.
I have a canvas of size 3583 �- 5049 pixels. The image within the png file is 2944x4454.
Just want to crop to 3000x4500, perhaps fill the background with white for the area outside the image
--- Post updated at 03:13 PM ---
I get
mountain.png PNG 3583x5049 3583x5049+0+0 8-bit DirectClass 912KB 0.000u 0:00.000
--- Post updated at 03:18 PM ---
bakunin:
OK, but what is the problem? Throw away the other 3 if you don't need them. Or do you want to autmate the process? If so, it would be nice to know your OS, your shell, ... you now the drill. Supposing you can use Korn shell and your system has the standard features how about this:
bakunin@host $ cat myconvert.sh
#! /bin/ksh
typeset fIn="$1"
typeset chExt=".png"
fIn="${fIn#${chExt}}"
if ! [ -f "${fIn}.${chExt}" ; then
print -u2 "Cannot find file ${fIn}.${chExt}."
exit 1
fi
if convert "$fIn.$chExt" -crop 3000x4500 +repage -format png "${fIn}--cr.${chExt}" ; then
rm "${fIn}-cr-1.${chExt}"
rm "${fIn}-cr-2.${chExt}"
rm "${fIn}-cr-3.${chExt}"
mv "${fIn}-cr-0.${chExt}" "${fIn}-cr.${chExt}"
exit 0
fi
exit $?
I hope this helps.
GNU Trisquel 7.0 with Gnome Version 3.8.4running bash
The task is to understand how it is creating the additional files, what are they? Has anybody encountered them before?
I also want to understand if my image is created properly. Are the headers correct, offset etc
--- Post updated at 03:26 PM ---
I now have tried, seem to work. Would this be ok, or do aybody have better suggestions?
convert mountain.png -format png -background white -flatten -crop 3000x4500 +repage mountain--cr.png
bakunin
December 10, 2018, 10:34am
11
Well, in this the bash version. You see why it is necessary to state your surroundings?
bakunin@host $ cat myconvert.sh
#! /bin/bash
local fIn="$1"
local chExt=".png"
fIn="${fIn#${chExt}}"
if ! [ -f "${fIn}.${chExt}" ; then
echo "Cannot find file ${fIn}.${chExt}." >&2
exit 1
fi
if convert "$fIn.$chExt" -crop 3000x4500 +repage -format png "${fIn}--cr.${chExt}" ; then
rm "${fIn}-cr-1.${chExt}"
rm "${fIn}-cr-2.${chExt}"
rm "${fIn}-cr-3.${chExt}"
mv "${fIn}-cr-0.${chExt}" "${fIn}-cr.${chExt}"
exit 0
fi
exit $?
kangol:
The task is to understand how it is creating the additional files, what are they? Has anybody encountered them before?
I also want to understand if my image is created properly. Are the headers correct, offset etc
This is a question best asked an expert in picture processing. I have never used this (or any other picture processing) program at all.
I hope this helps.
bakunin