How to crop this image so only the middle part remains ?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Rye
Posts: 158
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

How to crop this image so only the middle part remains ?

Post by Rye »

Example:

Image

Would be nice to also get an explanation.


Thanks in advance
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: How to crop this image so only the middle part remains ?

Post by Bonzo »

How much do you want to crop?

If you just want to remove the black lines on the sides you could add a black border to the whole image and then use -trim.

If you just wanted the star You could do as above and then add another -trim which should crop to the edges of the star.
Rye
Posts: 158
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

Re: How to crop this image so only the middle part remains ?

Post by Rye »

I want to crop the picture so only the white area remains.

As simple as possible.

Would be best if the command could be used on all png's in one folder (batch).
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: How to crop this image so only the middle part remains ?

Post by Bonzo »

So you are not even going to try it yourself after I gave you the explanation above?

Code: Select all

convert crop.png -bordercolor black -border 1x1 -trim output.jpg
I will let you work out how to work on multiple images as the question has been asked multiple times on the forum.
Rye
Posts: 158
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

Re: How to crop this image so only the middle part remains ?

Post by Rye »

Ok, trim actually "is" simple enough. Always dazzles me how ImageMagick simplyfies thes processes
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
Rye
Posts: 158
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

Re: How to crop this image so only the middle part remains ?

Post by Rye »

These didn't come out like I wanted (a small border remains):
[spoiler]
Image
Image
[/spoiler]

Ideas ?
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: How to crop this image so only the middle part remains ?

Post by Bonzo »

Your background is not exactly black; you need to add a -fuzz:

Code: Select all

convert crop.png -bordercolor black -border 1x1 -fuzz 10% -trim output.jpg
Post Reply