Cropping a file and putting it back together!

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
Mofler
Posts: 10
Joined: 2013-06-11T05:31:27-07:00
Authentication code: 6789

Cropping a file and putting it back together!

Post by Mofler »

Hi all!
I found this tool looking for a solution to a quite specific "problem".
I am quite fond of scripting (Powershell) and automating and I think that Imagemagick could be the perfect solution.

What I would like to do is the following:

I have an image that I would like to:
- Split up into four parts
- Leave the original base image
- Invert the outer three parts
- Save a new image

This is something I'm going to do quite often so I would love to have it automated.

I know that this is quite hard to grasp, so I've made the following drawing:
[img=http://s2.postimg.org/3o1mk66ut/Untitled.jpg]

(The letters are for referential purposes only and not part of the desired result).

Any starter help would be great. And if someone has tackled something similar I would LOVE to see how so I do not have to re-invent the wheel:)

Kind regards from Norway!
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: Cropping a file and putting it back together!

Post by GreenKoopa »

Welcome Mofler,

- Split up into four parts
Four equal parts? This creates four new images.
convert in.png -crop 50x50% out.png

- Invert the outer three parts
Invert the colors, or flip the orientation, or rearrange the pieces?
Mofler
Posts: 10
Joined: 2013-06-11T05:31:27-07:00
Authentication code: 6789

Re: Cropping a file and putting it back together!

Post by Mofler »

Thank you Greenkopa!

If you check my illustration here: http://postimg.org/image/3o1mk66ut/ you can see what I'd like to achieve.
I'd like to rearrange the pieces.

So now I have the original file, and four pieces. The thing I'd like to do is to put them back together again according to the above mentioned illustration.

And another thing, why is the thumbnail image (windows) showing the full image for all the smaller pieces?
Mofler
Posts: 10
Joined: 2013-06-11T05:31:27-07:00
Authentication code: 6789

Re: Cropping a file and putting it back together!

Post by Mofler »

So this is where I'm at:

Code: Select all

convert c:\temp\image.jpg -crop 50x50% part.jpg
convert -rotate 180 part-1.jpg part-1.jpg 
convert -rotate 180 part-2.jpg part-2.jpg 
montage -adjoin image.jpg part-1.jpg part-2.jpg part-0.jpg result.jpg
My problem is:
- The quality of result.jpg is REALLY low
- The image.jpg piece are resized to match the partX pices. I would like it to remain 100% (larger then the other pieces)

Any help is greaetly appreciated:)
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Cropping a file and putting it back together!

Post by Bonzo »

Your quaility problem is probably down to jpg compression. Save the intermediate images in a non compressed format; .miff is the Imagemagick format that would be good to use.

You may be able to do most of you want in one line but I do not understand your sketch. You have the original image without letters then an image with A, B, C and D. Then 3 other smaller images A, B and C; where did small D go?
Mofler
Posts: 10
Joined: 2013-06-11T05:31:27-07:00
Authentication code: 6789

Re: Cropping a file and putting it back together!

Post by Mofler »

Hi!
I actually sorted out the quality issue by adding -geometry

Code: Select all

montage -adjoin image.jpg part-1.jpg part-2.jpg part-0.jpg -geometry +2+2+2+2 result.jpg
I am not going to use small D.

How do I specify what tiles the different pieces should occupy? For example; I'd like part-1.jpg to be positioned at 3,2.
Is this possible?
Mofler
Posts: 10
Joined: 2013-06-11T05:31:27-07:00
Authentication code: 6789

Re: Cropping a file and putting it back together!

Post by Mofler »

I now see that my question has somewhat become different than I started out with, therefore I am posting a new one.
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: Cropping a file and putting it back together!

Post by GreenKoopa »

Code: Select all

convert -background white -gravity SouthEast ^
image.jpg part-1.jpg +append ^
( part-2.jpg part-0.jpg +append ) ^
-append ^
result.jpg
This should give you one idea, but:
You have not provided sample input and output, so this has not been tested.
What should happen if image.jpg is not evenly divisible?
The background could be any color, including transparent.
Borders or margins could be added if needed. I don't fully understand your diagram.
result.jpg will have the metadata from image.jpg. So do the pieces, including internal thumbnail.
These commands could be combined into one in the end. Otherwise, I'm with Bonzo that intermediate files should not be in jpg. Maybe miff or png.

EDIT: Sorry, I missed that we are moving to a new topic.
Post Reply