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

Wednesday, July 27, 2022

[FIXED] How to annotate a text on the top of a cropped image using ImageMagick

 July 27, 2022     bash, crop, image, imagemagick, linux     No comments   

Issue

I want to annotate a counter on the top of a series of images each cropped of an image. I wrote:

crop=1050x"$height"+0+"$top"
loc=90x90+10+"$top"
time=$((time-1))
convert $image -crop "$crop" -pointsize 24 -fill white -undercolor '#00000080' -gravity North -annotate $loc  "$time" "out/page_"$counter"_"$i".png"    

This is called in a loop and the variable top increases. So, I can see the counter on the top of first output image but not on the rest. It seems it first draws the counter on the original image and then crop it, so the counter disappears after crop.

I tried to use a $loc variable for the location of annotation but it also doesn't work!


Solution

When you "-crop" with ImageMagick you'll often need to add "+repage" right after the operation to set the paging geometry of the cropped piece(s) back to WxH+0+0. This can be important because some operations like "-annotate" will locate according to that geometry.

In your command, if you want the annotation the same distance from the top in every image, repage after the crop, and don't increment that distance with "$top" in the "$loc" variable. Just use the number of pixels you want the text to be down from the top.



Answered By - GeeMack
Answer Checked By - Terry (PHPFixing Volunteer)
  • 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

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 © PHPFixing