Center align object in a image
-
- Posts: 16
- Joined: 2016-01-11T05:12:11-07:00
- Authentication code: 1151
Center align object in a image
Platform: Windows
Imagemagick version: 6.9.3
Sample Image: http://imgur.com/81v7P6p
I have as set of images which have a object in it and the images are of different dimensions/resolutions. I want o batch process these to center align the objects. How do I do this?
Imagemagick version: 6.9.3
Sample Image: http://imgur.com/81v7P6p
I have as set of images which have a object in it and the images are of different dimensions/resolutions. I want o batch process these to center align the objects. How do I do this?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Center align object in a image
The image is centered horizontally (from appearance). the only issue is that there is no white at the bottom
By center do you mean equal white all around. If so, then trim and pad. So try
By center do you mean equal white all around. If so, then trim and pad. So try
Code: Select all
convert 81v7P6p.jpg -fuzz 10% -trim +repage -bordercolor white -border 20 result.jpg
-
- Posts: 16
- Joined: 2016-01-11T05:12:11-07:00
- Authentication code: 1151
Re: Center align object in a image
I shared the wrong sample. Here's the correct one http://imgur.com/Kw6mXbhfmw42 wrote:The image is centered horizontally (from appearance). the only issue is that there is no white at the bottom
By center do you mean equal white all around. If so, then trim and pad. So try
Code: Select all
convert 81v7P6p.jpg -fuzz 10% -trim +repage -bordercolor white -border 20 result.jpg
Re: Center align object in a image
Did you try fmw42's example code? If so what was wrong with the result?
-
- Posts: 16
- Joined: 2016-01-11T05:12:11-07:00
- Authentication code: 1151
Re: Center align object in a image
That code close crops the images and fills the border with white colour. What I want is to center align the object in the same canvas. The hex code will be the one shown in the second sample.Bonzo wrote:Did you try fmw42's example code? If so what was wrong with the result?
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Center align object in a image
Perhaps you want to effectively trim to the shoe but then back off the trim by a certain amount, say 10 pixels. Windows BAT script:
Code: Select all
rem Trim, but back off the trim.
set SRC=shoe.jpg
set OUT=s.jpg
set delta=10
for /F "usebackq tokens=1-4 delims=x+" %%A in (`%IM%convert ^
%SRC% -fuzz 10%% -format %%@ info:`) do (
set /A W=%%A+2*delta
set /A H=%%B+2*delta
set /A X=%%C-delta
set /A Y=%%D-delta
)
echo %W%x%H%+%X%+%Y%
%IM%convert %SRC% -crop %W%x%H%+%X%+%Y% +repage %OUT%
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: Center align object in a image
try this:
Unix syntax:
I think Windows syntax:
Unix syntax:
Code: Select all
convert Kw6mXbh.jpg -fuzz 1% -trim +repage \
-virtual-pixel edge -set option:distort:viewport \
"%[fx:max(w,h)+10]x%[fx:max(w,h)+10]+%[fx:(w-max(w,h)-10)/2]+%[fx:(h-max(w,h)-10)/2]" \
-filter point +distort SRT 0 Kw6mXbh_center.jpg
Code: Select all
convert Kw6mXbh.jpg -fuzz 1% -trim +repage ^
-virtual-pixel edge -set option:distort:viewport ^
"%[fx:max(w,h)+10]x%[fx:max(w,h)+10]+%[fx:(w-max(w,h)-10)/2]+%[fx:(h-max(w,h)-10)/2]" ^
-filter point +distort SRT 0 Kw6mXbh_center.jpg
-
- Posts: 1
- Joined: 2017-12-21T10:52:10-07:00
- Authentication code: 1152
Re: Center align object in a image
Trying to use this code, but getting a bug on this line: `for /F "usebackq tokens=1-4 delims=x+" %%A in (`%IM%convert ^`snibgo wrote: ↑2016-04-01T04:07:32-07:00 Perhaps you want to effectively trim to the shoe but then back off the trim by a certain amount, say 10 pixels. Windows BAT script:Code: Select all
rem Trim, but back off the trim. set SRC=shoe.jpg set OUT=s.jpg set delta=10 for /F "usebackq tokens=1-4 delims=x+" %%A in (`%IM%convert ^ %SRC% -fuzz 10%% -format %%@ info:`) do ( set /A W=%%A+2*delta set /A H=%%B+2*delta set /A X=%%C-delta set /A Y=%%D-delta ) echo %W%x%H%+%X%+%Y% %IM%convert %SRC% -crop %W%x%H%+%X%+%Y% +repage %OUT%
Not sure why the /F is there or if that is causing the issue. The bug says there is a syntax error here. Please let me know what additional information I should include.
Thanks
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Center align object in a image
What version of IM are you running? If v7, you should change "convert" to "magick". On what platform? (I assume Windows, but perhaps not.)
I use %IM% to point to the directory that contains convert.exe. If you don't, then you can remove %IM%.
It might help if you paste the complete contents of your BAT file.
Please paste the exact error message.cajun20/20 wrote:The bug says there is a syntax error here.
I use %IM% to point to the directory that contains convert.exe. If you don't, then you can remove %IM%.
It might help if you paste the complete contents of your BAT file.
snibgo's IM pages: im.snibgo.com