PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, July 26, 2022

[FIXED] How to crop to equally sized tiles using GraphicsMagick?

 July 26, 2022     crop, graphicsmagick, imagemagick, tiles     No comments   

Issue

Is it possible to crop equally sized tiles using GraphicsMagick, similar to ImageMagick's crop "@" modifier?

convert montage.gif -crop 5x1@ +repage +adjoin montage_%d.gif

Is it possible to use GraphicsMagick's crop "%" modifier, if the height of the image dimensions are constant?

Sample image directly from the ImageMagick manual:

https://legacy.imagemagick.org/Usage/crop/montage.gif

I would like to divide the sample image into 5 equal tiles, as shown in the ImageMagick manual.


Solution

You can maybe let bash do the work for you instead:

# Get height and width of image
read h w < <(gm identify -format "%h %w" montage.gif)  

# Crop into 5 full-height, equal width parts
gm convert montage.gif -crop $((w/5))x$h +adjoin result%d.jpg

You can maybe let shell do the work for you instead:

gm convert montage.gif -trim -gravity center trimmed.gif;

d=$(gm identify -format "%h %w" trimmed.gif); h=$(echo $d | grep -ioE "([0-9]+\s)"); w=$(echo $d | grep -ioE "(\s[0-9]+)"); echo $h; echo $w;

gm convert trimmed.gif -gravity center -crop $((w/5))x$h +adjoin result%d.jpg


Answered By - Mark Setchell
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,205,009

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing