Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding caption on image #92

Open
stonetwig opened this issue Jan 4, 2021 · 1 comment
Open

Adding caption on image #92

stonetwig opened this issue Jan 4, 2021 · 1 comment

Comments

@stonetwig
Copy link

Hello, I use your library and thanks for all the great work

This "issue" is more of a question than anything else.
I am trying to add a caption onto an image but I think I am failing to understand how to use the custom method or if it even is supported?

This is what I have come up with when trying to add a caption via the convert command in imagemagick:

open(image_path)
        |> custom("convert", "-background '#0008' -fill white -gravity center -size 50x30 caption:my caption")
        |> save(path: image_path)

Is it possible somehow or is it not yet supported?

Thanks in advance

@bunnymatic
Copy link
Contributor

bunnymatic commented Jan 30, 2021

I'm not an owner/maintainer here but I don't believe that is supported yet. label and caption and annotate which are all ways to get text on an image require special command processing.

The following

filename |> 
  Mogrify.open |> 
  Mogrify.custom("label","the caption") |> 
  Mogrify.custom("gravity","center") |>   
  Mogrify.custom("fill","red") |> 
  Mogrify.save(path: "out.jpg")

generates a command like this:

mogrify -label "the caption" -gravity center -size 100x100 -fill red -write out.jpg inputfile.jpg

The problem here is that -label "the caption" is the wrong format for building labels. The command really needs a command that includes label:'the label' and it can't go wherever - it has to be in the right place within the command (after all the options i think). Additionally, when you use ImageMagick to create a label or caption, it is really just generating an image with that label. To get it on top of another image you need to combine them with composite.

I think to get the support out of this library, it probably needs a couple of custom command helpers that could deal with label and composite and putting the whole thing together. If you check out the code, there is a custom method to generate a histogram which is also a command in ImageMagick that needs some custom argument construction. That might be an example of how that functionality could be added to the library.

These links (ImageMagick docs and a SO post) should give some context:

  • (ImageMagick docs on label)[https://legacy.imagemagick.org/Usage/text/#label]
  • (SO Post: imagemagick place caption on existing image)[
    https://stackoverflow.com/questions/36701114/imagemagick-place-caption-on-existing-image]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants