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?".
I want to trim the dimensions, dimension lines which are present around the window drawing and preserve only the window image. How can do that using Image Magick ?
Version: ImageMagick 7.0.5-5 Q16 x86_64 2017-04-25
Running on macOS Sierra 10.12.5
Please do not double post to two different forums.
Do you want to trim this diagram or an image to this format? If the latter, then please supply an input image. If the former, what area do you want left -- the white center only?
Is this what you want? I change all white to black, then get the trim coordinates, then crop the originals using the trim coordinates. You would be better off using a non-compressed format for your diagram, such as png or tif.
The command probably will not work in mogrify. The explanation is above my result.
-write mpr:img (saves a copy of the input)
-fuzz 10% -fill black -opaque white (changes all white to black)
-set option:cropvals "%@" (saves the trim values as cropvals without having to use -trim)
+delete mpr:img (deletes the previous version that had black replacing white and reloads the input image)
-crop "%[cropvals]" +repage (crops the input image using the stored cropvals)
My command works on IM 7.0.5-10 Q16 Mac OSX Sierra. So perhaps you need to upgrade ImageMagick, unless you copied the command and it got split to more than one line. If so, make sure you edit the command so that it is one command on one long line of text. Then copy that and paste into a terminal window.
I suggest if you want to use this on lots of images, you write a script loop over each image and then call this command.
One issue is that your images are jpg. This means they are compressed and the solid areas of colors are not going to be perfectly uniform. Thus the -fuzz 10% may need to be changed for each image. That is why I suggested that your input images be non-lossy-compressed formats such as png or tif. Then the -fuzz should not be needed. However, you cannot just change jpg to png, since the loss is already there now.
fmw42 wrote: ↑2017-06-06T10:53:09-07:00
The command probably will not work in mogrify. The explanation is above my result.
-write mpr:img (saves a copy of the input)
-fuzz 10% -fill black -opaque white (changes all white to black)
-set option:cropvals "%@" (saves the trim values as cropvals without having to use -trim)
+delete mpr:img (deletes the previous version that had black replacing white and reloads the input image)
-crop "%[cropvals]" +repage (crops the input image using the stored cropvals)
My command works on IM 7.0.5-10 Q16 Mac OSX Sierra. So perhaps you need to upgrade ImageMagick, unless you copied the command and it got split to more than one line. If so, make sure you edit the command so that it is one command on one long line of text. Then copy that and paste into a terminal window.
I suggest if you want to use this on lots of images, you write a script loop over each image and then call this command.
One issue is that your images are jpg. This means they are compressed and the solid areas of colors are not going to be perfectly uniform. Thus the -fuzz 10% may need to be changed for each image. That is why I suggested that your input images be non-lossy-compressed formats such as png or tif. Then the -fuzz should not be needed. However, you cannot just change jpg to png, since the loss is already there now.
Thanks for the super explanation
The crop issue was resolved as I upgraded the Image Magick to version 7.0.5-10 Q16.
I will surely incorporate your suggestion of working with png/tiff images.