Page 1 of 1

Cropping a file and putting it back together!

Posted: 2013-06-11T05:43:53-07:00
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!

Re: Cropping a file and putting it back together!

Posted: 2013-06-11T06:36:09-07:00
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?

Re: Cropping a file and putting it back together!

Posted: 2013-06-12T02:23:37-07:00
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?

Re: Cropping a file and putting it back together!

Posted: 2013-06-12T04:22:05-07:00
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:)

Re: Cropping a file and putting it back together!

Posted: 2013-06-12T04:50:41-07:00
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?

Re: Cropping a file and putting it back together!

Posted: 2013-06-12T06:22:29-07:00
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?

Re: Cropping a file and putting it back together!

Posted: 2013-06-12T06:38:09-07:00
by Mofler
I now see that my question has somewhat become different than I started out with, therefore I am posting a new one.

Re: Cropping a file and putting it back together!

Posted: 2013-06-12T06:43:35-07:00
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.