Giter VIP home page Giter VIP logo

mogrify's Introduction

Mogrify

Build Status Module Version Hex Docs Total Download License Last Updated

An Elixir wrapper for ImageMagick command line.

Documentation: https://hexdocs.pm/mogrify/

Requirements

You must have ImageMagick installed of course.

Installation

Add this to your mix.exs file, then run mix do deps.get, deps.compile:

def deps do
  {:mogrify, "~> 0.9.3"}
end

Configuration

Configure the ImageMagick executable paths (optional):

Configure mogrify command:

config :mogrify, mogrify_command: [
  path: "magick",
  args: ["mogrify"]
]

Configure convert command:

config :mogrify, convert_command: [
  path: "magick",
  args: ["convert"]
]

Configure identify command:

config :mogrify, identify_command: [
  path: "magick",
  args: ["identify"]
]

Examples

Thumbnailing:

import Mogrify

# This does operations on an original image:
open("input.jpg") |> resize("100x100") |> save(in_place: true)

# save/1 creates a copy of the file by default:
image = open("input.jpg") |> resize("100x100") |> save
IO.inspect(image) # => %Image{path: "/tmp/260199-input.jpg", ext: ".jpg", ...}

# Resize to fill
open("input.jpg") |> resize_to_fill("450x300") |> save

# Resize to limit
open("input.jpg") |> resize_to_limit("200x200") |> save

# Extent
open("input.jpg") |> extent("500x500") |> save

# Gravity
open("input.jpg") |> gravity("Center") |> save

Converting:

import Mogrify

image = open("input.jpg") |> format("png") |> save
IO.inspect(image) # => %Image{path: "/tmp/568550-input.png", ext: ".png", format: "png"}

Getting info:

import Mogrify

image = open("input.jpg") |> verbose
IO.inspect(image) # => %Image{path: "input.jpg", ext: ".jpg", format: "jpeg", height: 292, width: 300}

Getting reduced info in a "lighter" way (uses less memory):

import Mogrify

info = identify("input.jpg")
IO.inspect(info) # => %{format: "jpeg", height: 292, width: 300}

Using custom commands to create an image with markup:

import Mogrify

%Mogrify.Image{path: "test.png", ext: "png"}
|> custom("size", "280x280")
|> custom("background", "#000000")
|> custom("gravity", "center")
|> custom("fill", "white")
|> custom("font", "DejaVu-Sans-Mono-Bold")
|> custom("pango", ~S(<span foreground="yellow">hello markup world</span>))
|> create(path: ".")

Plasma backgrounds:

import Mogrify

%Mogrify.Image{path: "test.png", ext: "png"}
|> custom("size", "280x280")
|> custom("seed", 10)
|> custom("plasma", "fractal")

Creating new images: See mogrify_draw for an example of generating a new image from scratch.

Changelog

See the changelog for important release notes between Mogrify versions.

Copyright and License

Copyright (c) 2014 Dmitry Vorotilin

Mogrify source code is licensed under the MIT License.

mogrify's People

Contributors

amarantedaniel avatar augustorsouza avatar caldwellysr avatar connorrigby avatar gustavocaso avatar kamilzielinski avatar kianmeng avatar kpanic avatar kyasu1 avatar markzsombor avatar mguterl avatar michelson avatar nitsujw avatar notdevinclark avatar parallel588 avatar peaceful-james avatar rkmax avatar route avatar talklittle avatar zamith avatar zkat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mogrify's Issues

(RuntimeError) missing prerequisite: 'convert'

Following code raises this error:

defmodule ImageText do
  @moduledoc """
  Documentation for `ImageText`.
  """

  @doc """
  Hello world.

  ## Examples

      iex> ImageText.hello()
      :world

  """
  def hello do
    :world
  end

  def create do
    import Mogrify

    %Mogrify.Image{path: "test.png", ext: "png"}
    |> custom("size", "280x280")
    |> custom("background", "#000000")
    |> create(path: ".")
  end
end

Full traceback:

C:\expro\image_text>iex -S mix
Interactive Elixir (1.13.0) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> ImageText.hello()
:world
iex(2)> ImageText.create()
** (RuntimeError) missing prerequisite: 'convert'
    (mogrify 0.9.1) lib/mogrify.ex:421: Mogrify.cmd_magick/3
    (mogrify 0.9.1) lib/mogrify.ex:80: Mogrify.create/2

File/Directory names with spaces are throwing errors

I noticed that when you try and use verbose on an image with spaces in its name, or technically anywhere within its path, that it would throw an error. Like so:

** (MatchError) no match of right hand side value: {"mogrify: unable to open image `/home/username/dir/mogrify/test/fixtures/ben\\': No such file or directory @ error/blob.c/OpenBlob/2712.\nmogrify: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.\nmogrify: unable to open image `der.jpg': No such file or directory @ error/blob.c/OpenBlob/2712.\n", 1}

I added a test in the repo where you simply try to call verbose on the @fixture_with_space variable and it fails. I am preparing a PR to fix this.

The issue falls with the ~w() function call, you are passing in the path/file name and substituting spaces with "// " but that does not properly sanitize the string to work with the ~w() function

Will link it here soon. It will also update all functions that use anything that could have a space, also will be updating tests as well.

Not an issue: identify.

Good afternoon,

Fun package! Keep up the good work.
How about having the identify command available in Mogrify? It would be a very valuable addition. My concern is that one cannot really get the result of identify using the custom command, right?

I'm aware that identify is not part of the mogrify toolkit. Documentation is here A good start would be to have a way to attach the mime-type of an image to the image struct :)

Cheers!
Doodloo

System.cmd should call `magick mogrify` instead of `mogrify`

When using the portable binary version of imagemagick, the correct command on unix systems is magick mogrify.

https://github.com/route/mogrify/blob/master/lib/mogrify.ex#L381

the direct call to mogrify would only apply when installed from source (if i'm not mistaken).
I receive the following error tuple when attempting to save using Mogrify.save/2:

{:error, %ErlangError{original: :enoent}}

Full error is as follows:

iex(1)> Mogrify.open("~/Downloads/test.jpg") |> Mogrify.save()
** (ErlangError) Erlang error: :enoent
    (elixir) lib/system.ex:791: System.cmd("mogrify", ["-write", "/tmp/255784-test.jpg", "/home/ziinc/Downloads/test.jpg"], [stderr_to_stdout: true])
    (mogrify) lib/mogrify.ex:28: Mogrify.save/2
iex(1)> 

I have tried writing a bash function in ~/.bashrc that points to magick but I think System.cmd calls the sh instead.

[Question] - Conversion from HEIC to jpg

This is not an issue with the lib, just a question about it:

Is the conversion from HEIC as clean as to png? Looks like ImageMagic supports the conversion, so I was wondering if folks here have had experience with it before.

image = open("input.heic") |> format("jpg") |> save

If the above "just works" it would be amazing.

Thanks for the lib!

Base64 to img?

Hey,

I'm currently stuck on resizing an image which I get from the param body as a base64 file.
My plan is to resize the file/image without saving it first and reopen it using the open function from Mogrify
Is there any way?

Cheers

create new image with background fails

I have tried to create a simple image with a black background but that didn't work, the image was not created but no error was returned

%Mogrify.Image{} 
|> Mogrify.custom("size", "280x280") 
|> Mogrify.custom("background", "#000000") 
|> Mogrify.create(path: "/tmp/new.jpg")

After some investigation it looks like the background is not accepted and the argument should be canvas instead:
https://stackoverflow.com/questions/39504522/create-blank-image-in-imagemagick

Using canvas instead didn't work either

%Mogrify.Image{} 
|> Mogrify.custom("size", "280x280") 
|> Mogrify.custom("canvas", "#000000") 
|> Mogrify.create(path: "/tmp/new.jpg")

Is this a bug?

If so do you want a PR?

Failing test(s) due to different resize output on Windows and Linux

I tried to run tests on Windows but for some reason, my image was off by 1px which caused tests to fail.
One of them that I focused on:

test ".save in place when file name has spaces" do
    # setup, make a copy
    File.mkdir_p!(@temp_test_directory)
    open(@fixture) |> save(path: @temp_image_with_space)

    # test begins
    image = open(@temp_image_with_space) |> resize("600x600") |> save(in_place: true) |> verbose
    assert %Image{path: @temp_image_with_space, height: 584, width: 600} = image

    File.rm_rf!(@temp_test_directory)
  end

The results it gives me are:

  • Windows: 600x585 (45.5kb)
  • Linux: 600x584 (49kb)

It seems like due to different OS (as I tested that on WSL and Windows on the same machine, so architecture shouldn't make a difference here) it gives me different results. Maybe it's related to that issue as well, I'm not sure now as I don't know how ImageMagick works underneath.
I think we should find a better way to compare it between these 2 different systems. I'll be trying to solve it but it would be good if you could put some ideas here as well as maybe you are aware of something I could use.
A simple, dirty but working idea for now could be doing asserts depending on the system they run on the same as we did for running mogrify commands on Windows in the past as they work a little bit different. WDYT?
I'll also check other tests if the issue is somehow common so we can solve it globally in the same way.

Format isn't applied if an image is saved without an extension

Expected

I can format and save an image without an extension, like so:

import Mogrify

open("image.jpg")
|> format("png")
|> save(path: "no_extension") 

open("no_extension")
|> verbose # Has type of png, even though there's no extension

Actual

When performing the above actions, the newly saved file maintains its original type

Workaround

import Mogrify

image = open("image.jpg")
  |> format("png")
  |> save()

File.rename(image.path, "no_extension")

open("no_extension")
|> verbose # Has type of png, as expected

Adding a watermark

I think it is not possible yet to add another picture with an watermark on top of an image.
Are you considering that?
Thank you.

Image struct is not updated with new format when saved in-place

I install magick on my windows and when I execute this code

              Mogrify.open(absolute <> "/" <> id <> "/" <> volid <> "/" <> filename)
              |> Mogrify.format("webp")
              |> Mogrify.save(in_place: true)
              |> IO.inspect()

It passed good, but images don't convert to webp.
Moreover inspect print this

%Mogrify.Image{
  animated: false,
  buffer: nil,
  dirty: %{},
  ext: ".png",
  format: "webp",
  frame_count: 1,
  height: nil,
  operations: [],
  path: "e:/code/archive/files/23/22/017.png",
  width: nil
}

To the console.

"ext:" still .png, but if we check out example from README.md ext was changed.

Annotate only prints one word of the annotation

Trying to build an image I'm having trouble with multi-word annotations.

    priv = to_string(:code.priv_dir(:jobs))
    save_url = priv <> "/tmp.png"

    text = "This is a test"

    %Mogrify.Image{}
    |> Mogrify.custom("size", "800x500")
    |> Mogrify.canvas("white")
    |> Mogrify.custom("fill", "black")
    |> Mogrify.custom("annotate", "+15+15 #{text}")
    |> Mogrify.create(path: save_url)

The resulting image just has "This".

Write to standard out

Does this library have the ability to create an image and then write to standard out without having to interact with the file system?

Print the command-line command during, or instead of, execution

Case 1: A configuration option to log the command when it is run.

Case 2: A dry_run option to skip running the command, and instead return the command that would be run. Either a binary string, or a tuple of {command, [args]} as would be passed to System.cmd/3

Histogram doesn't seem to support srgba color sets...

With the right (wrong) image, we have a histogram like this from image magic

     708: (  0,  0,  0,255) #000000 black
      20: (  0,  0, 85,255) #000055 srgba(0,0,85,1)
...

  187444: (255,255,255,255) #FFFFFF white

and i believe the pattern matcher to extract a struct of color data from here doesn't work.

I put the histogram function together and will hopefully have a PR soon. and will flesh out this report.

Trying to setup testing on mac.

Trying to get some testing working but running into issue.

As far as I can tell I have ImageMagick 7.0.8-21 installed.

~/Dev/elixir/mogrify master
❯ convert -version

Version: ImageMagick 7.0.8-21 Q16 x86_64 2018-12-28 https://imagemagick.org
Copyright: © 1999-2019 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules
Delegates (built-in): bzlib freetype jng jp2 jpeg lcms ltdl lzma png tiff webp xml zlib

But when trying to run the tests.

~/Dev/elixir/mogrify master
❯ mix test
....

  1) test pango by using single quotes (MogrifyTest)
     test/mogrify_test.exs:154
     Assertion with == failed
     code:  assert File.exists?(path) == true
     left:  false
     right: true
     stacktrace:
       test/mogrify_test.exs:162: (test)

......

  2) test binary output (MogrifyTest)
     test/mogrify_test.exs:192
     ** (MatchError) no match of right hand side value: {"convert: unable to open image '<span foreground=\"yellow\">hello test</span>': No such file or directory @ error/blob.c/OpenBlob/3492.\nconvert: no decode delegate for this image format `PANGO' @ error/constitute.c/ReadImage/556.\nconvert: no images defined `png:-' @ error/convert.c/ConvertImageCommand/3300.\n", 1}
     code: |> create(buffer: true)
     stacktrace:
       (mogrify) lib/mogrify.ex:48: Mogrify.create/2
       test/mogrify_test.exs:197: (test)

........

  3) test pango success (MogrifyTest)
     test/mogrify_test.exs:140
     Assertion with == failed
     code:  assert File.exists?(path) == true
     left:  false
     right: true
     stacktrace:
       test/mogrify_test.exs:148: (test)



  4) test binary output using into: IO.stream/2 (MogrifyTest)
     test/mogrify_test.exs:202
     ** (MatchError) no match of right hand side value: {%IO.Stream{device: :standard_io, line_or_bytes: :line, raw: true}, 1}
     code: capture_io(fn ->
     stacktrace:
       (mogrify) lib/mogrify.ex:48: Mogrify.create/2
       test/mogrify_test.exs:209: anonymous fn/0 in MogrifyTest."test binary output using into: IO.stream/2"/1
       (ex_unit) lib/ex_unit/capture_io.ex:150: ExUnit.CaptureIO.do_capture_io/2
       (ex_unit) lib/ex_unit/capture_io.ex:120: ExUnit.CaptureIO.do_capture_io/3
       test/mogrify_test.exs:204: (test)

.

  5) test pango by wrapping in <markup /> tags (MogrifyTest)
     test/mogrify_test.exs:168
     Assertion with == failed
     code:  assert File.exists?(path) == true
     left:  false
     right: true
     stacktrace:
       test/mogrify_test.exs:176: (test)

..

  6) test binary output buffer matches file output (MogrifyTest)
     test/mogrify_test.exs:217
     ** (MatchError) no match of right hand side value: {"convert: unable to open image '<span foreground=\"yellow\">hello test</span>': No such file or directory @ error/blob.c/OpenBlob/3492.\nconvert: no decode delegate for this image format `PANGO' @ error/constitute.c/ReadImage/556.\nconvert: no images defined `png:-' @ error/convert.c/ConvertImageCommand/3300.\n", 1}
     code: result1 = image |> custom("stdout", "png:-") |> create(buffer: true)
     stacktrace:
       (mogrify) lib/mogrify.ex:48: Mogrify.create/2
       test/mogrify_test.exs:222: (test)

.............

Finished in 2.8 seconds
40 tests, 6 failures

Thoughts?

Save not working

Hi, I want to greatly commend the great work done with this library.

Please i'm having issue trying to resize using the following syntax

{:mogrify, "~> 0.6.1"}

I'm run on terminal

Mogrify.open("test.jpg") |> Mogrify.resize("100x100") |> Mogrify.save

and error output

** (ErlangError) Erlang error: :enoent
    (elixir) lib/system.ex:605: System.cmd("mogrify", ["-resize", "100x100", "-write", "/tmp/977056-test.jpg", "/opt/app/test.jpg"], [stderr_to_stdout: true])
    lib/mogrify.ex:26: Mogrify.save/2

Please how can i resolve this? Thanks.

image not saved if the folder doesn't exist

Following code doesn't create an image because the folder doesn't exist.

          path
          |> Mogrify.open()
          |> Mogrify.resize(width)
          |> Mogrify.save(path: File.cwd!() <> "/priv/media/" <> filename)

I can obviously check if the directory exists and create it before saving the image, but is this something that Mogrify.save() should be doing or should it at least throw an error?

extract_histogram_data is broken `Enumerable not implemented for nil of type Atom`

In a recent mod, it appears that extract_histogram_data no longer works. When I run tests (on a project that includes mogrify), I get the following error

     ** (Protocol.UndefinedError) protocol Enumerable not implemented for nil of type Atom. This protocol is implemented for the following type(s): HashSet, Range, Map, Function, List, Stream, Date.Range, HashDict, GenEvent.Stream, MapSet, File.Stream, IO.Stream
     code: assert @fixture |> ImageProcessor.Impl.compute_theme(:simple_sort) ==
     stacktrace:
       (elixir 1.11.2) lib/enum.ex:1: Enumerable.impl_for!/1
       (elixir 1.11.2) lib/enum.ex:141: Enumerable.reduce/3
       (elixir 1.11.2) lib/enum.ex:3461: Enum.map/2
       (mogrify 0.8.0) lib/mogrify.ex:127: Mogrify.extract_histogram_data/1
...

I'm going to look into the issue and hopefully can have a PR up soon to address this.

I wanted to just document the fact that it's out there in case someone else has noticed issues.

Convert image in webp

Can I convert a jpg in webp?

in my shell I can do it with

convert foo.jpg -quality 50 wizard.webp

In my module I try with

image = Mogrify.open("public/foo.jpg")
Mogrify.image_operator(image, "convert public/foo.jpg -quality 50 public/wizard.webp") |> create(in_place: true)

the output is {:ok}, but I don't have wizard.webp

Elixir 1.3 warnings

warning: the variable "cols" is unsafe as it has been set inside a case/cond/receive/if/&&/||. Please explicitly return the variable value instead. For example:

    case int do
      1 -> atom = :one
      2 -> atom = :two
    end

should be written as

    atom =
      case int do
        1 -> :one
        2 -> :two
      end

Unsafe variable found at:
  lib/mogrify.ex:152

warning: the variable "rows" is unsafe as it has been set inside a case/cond/receive/if/&&/||. Please explicitly return the variable value instead. For example:

    case int do
      1 -> atom = :one
      2 -> atom = :two
    end

should be written as

    atom =
      case int do
        1 -> :one
        2 -> :two
      end

Unsafe variable found at:
  lib/mogrify.ex:152

warning: the variable "image" is unsafe as it has been set inside a case/cond/receive/if/&&/||. Please explicitly return the variable value instead. For example:

    case int do
      1 -> atom = :one
      2 -> atom = :two
    end

should be written as

    atom =
      case int do
        1 -> :one
        2 -> :two
      end

Unsafe variable found at:
  lib/mogrify.ex:153

warning: the variable "image" is unsafe as it has been set inside a case/cond/receive/if/&&/||. Please explicitly return the variable value instead. For example:

    case int do
      1 -> atom = :one
      2 -> atom = :two
    end

should be written as

    atom =
      case int do
        1 -> :one
        2 -> :two
      end

Unsafe variable found at:
  lib/mogrify.ex:155

Image.width and height should be parsed into integers

Currently width and height are binaries, so consumers of the mogrify library must parse them.

The library should parse them into integers.

Breaking change; would need to bump library version.

Created this issue for tracking purposes. Already have PR #24

Avoid changing file modified time if unmodified

The mogrify command line tool is meant to overwrite existing files 1. As such, even if you do mogrify -verbose image.jpg it will touch image.jpg and update its modification time. Would be ideal if this could be avoided.

Proposal for API changes

Hey @route, I am curious what you think about a few changes that I would like to propose. I have been working on these changes, but I wanted to run them by you before I submit a PR.

Batch operations into a single command / copy by default

Right now if you want to change the format and resize an image, it will invoke the mogrify command multiple times. Instead I propose that we batch the operations and run them as a single invocation of mogrify.

One of the principals of Elixir is immutability and I think it would be awesome if mogrify embraced this too. Instead of defaulting to modifying the existing image on the filesystem, I think it would be interesting to default to creating a new image.

Current

If we wanted to resize, format, an image without overwriting the original we would:

open("input.jpg") |> copy |> resize("100x100") |> format("png")

This will invoke mogrify twice, once to resize, and once to change the format.

Proposed

Save to a temporary directory

image = open("input.jpg") |> resize("100x100") |> format("png") |> save
image.path # => some path in the temp directory

Save to an explicit path

image = open("input.jpg") |> resize("100x100") |> format("png") |> save("new.png")

What do you think? Is this something that you would be interested in merging into mogrify?

Create not working

Hi, I want to greatly commend the great work done with this library.

Please i'm having issue trying to create a thumbnail using the following syntax

{:mogrify, "~> 0.6.1"}

resized =
              %Mogrify.Image{path: upload_path}
              |> custom("thumbnail", "480x480")
              |> custom("strip")
              |> custom("gravity", "center")
              |> custom("extent", "480x480")
              |> create(in_place: true)

Please how can i resolve this? Thanks.

Mogrify.create to buffer failing

Hi,

I'm experimenting with the new buffer feature, but I'm running into an error when I call create.

I have an image, created from scratch.

If I call img |> Mogrify.create(path: "/tmp/test.png"), I get the image written to disk as I expect. However when I call img |> Mogrify.create(buffer: true), I get the following error:

** (MatchError) no match of right hand side value: {"convert: missing an image filename `line 76.000000, 24.520066 78.000000, 54.047279' @ error/convert.c/ConvertImageCommand/3255.\n", 1}
    (mogrify) lib/mogrify.ex:48: Mogrify.create/2

Adding text to an image

I have an image that I want to add text to. For some reason the image will open and save a copy without any issues but I can't get the copy to be changed in any way.

    img_url = to_string(:code.priv_dir(:jobs)) <> "/tristar.png"
    save_url = to_string(:code.priv_dir(:jobs)) <> "/tristar_copy.png"

    Mogrify.open(img_url)
    |> Mogrify.custom("pointsize", 200)
    |> Mogrify.custom("gravity", "North")
    |> Mogrify.custom("annotate", "+0,+100 'Testing'")
    |> IO.inspect(label: "\n===== Image Pre-Save =============================================")
    |> Mogrify.save(path: save_url)

The output in Iex looks like:

===== Image Pre-Save =============================================:
%Mogrify.Image{
  animated: false,
  buffer: nil,
  dirty: %{},
  ext: ".png",
  format: nil,
  frame_count: 1,
  height: nil,
  operations: [
    {"pointsize", 200},
    {"gravity", "North"},
    {"annotate", "+0,+100 'Testing'"}
  ],
  path: "/code/elixir/_build/dev/lib/jobs/priv/tristar.png",
  width: nil
}
%Mogrify.Image{
  animated: false,
  buffer: nil,
  dirty: %{},
  ext: ".png",
  format: nil,
  frame_count: 1,
  height: nil,
  operations: [],
  path: "/code/elixir/_build/dev/lib/jobs/priv/tristar_copy.png",
  width: nil
}

I've tried adding fill and stroke with custom. I've tried using label, draw text, and annotate. The saved image at the end is simply a copy of the original.

When I try to use create instead of save nothing happens.

Image with Tilde

After this operation on my image

Mogrify.open("foojpg") |> Mogrify.image_operator("convert foo.jpg -auto-level -sharpen 0x2.1") |> Mogrify.save(path: "public/bar.jpg")

in my Folder I have two files

bar.jpg and
bar.jpg~

Can I avoid bar.jpg~ ?

My version is:

identify -version
Version: ImageMagick 6.8.9-9 Q16 x86_64 2017-07-15 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC Modules OpenMP
Delegates: bzlib cairo djvu fftw fontconfig freetype jbig jng jpeg lcms lqr ltdl lzma openexr pangocairo png rsvg tiff wmf x xml zlib

Adding caption on image

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

Can I get size of buffered image?

I want to render image blocks and then combine them into big one. To do this I need to calculate width and height of buffered images. I wrote this code with images manipulations that I looking for

Image attributes are missing

Why am I not seeing more information after I open an image via a path?

  def scale_image(path) do
    path
    |> IO.inspect()
    |> open()
    |> IO.inspect()
    |> resize("1024x683>")
    |> IO.inspect()
    |> save()
    |> IO.inspect()
  end

returns

"/var/folders/4b/9bp6zj4j7b91w70w_vb5hw7c0000gn/T//plug-1545/multipart-1545853213-852947363977028-4"
%Mogrify.Image{
  animated: false,
  dirty: %{},
  ext: "",
  format: nil,
  frame_count: 1,
  height: nil,
  operations: [],
  path: "/var/folders/4b/9bp6zj4j7b91w70w_vb5hw7c0000gn/T/plug-1545/multipart-1545853213-852947363977028-4",
  width: nil
}
%Mogrify.Image{
  animated: false,
  dirty: %{},
  ext: "",
  format: nil,
  frame_count: 1,
  height: nil,
  operations: [resize: "1024x683>"],
  path: "/var/folders/4b/9bp6zj4j7b91w70w_vb5hw7c0000gn/T/plug-1545/multipart-1545853213-852947363977028-4",
  width: nil
}
%Mogrify.Image{
  animated: false,
  dirty: %{},
  ext: "",
  format: nil,
  frame_count: 1,
  height: nil,
  operations: [],
  path: "/var/folders/4b/9bp6zj4j7b91w70w_vb5hw7c0000gn/T/276900-multipart-1545853213-852947363977028-4",
  width: nil
}

from what I can tell all the operations work as expected but meta data such as ext or width / height information looks to be getting left out. Why?

Mogrify.create/2 doesn't work on existing image

Here I want to use convert to resize an image. Mogrify.create/2 is using convert underneath.

import Mogrify

open("/tmp/old.jpg")
|> resize_to_fill("100x100")
|> create(path: "/tmp/new.jpg")

However no image was created. Change the last line to save(path: "/tmp/new.jpg") works though.

New release on hex?

Hey, I've just been scratching my head as to why resize_to_fill wasn't working... turns out the version on hex.pm is out of date, is there any chance of getting the current code on there?

Issue overwriting image when in_place is not specified

Running into an recent issue when using mogrify 0.8.0 to generate a thumbnail. It is generating the thumbnail file with the specified name, but it is also overwriting the original file with the thumbnail.

src = Path.join(folder, filename)
dest = Path.join(folder, "thumb_#{filename}")

src
|> Mogrify.open()
|> Mogrify.resize_to_limit(@thumb_size)
|> Mogrify.save(path: dest)
|> Map.get(:path)

I think this issue started when upgrading to the latest imagemagick: stable 7.0.11-13.

Wondering if you have any insights or if you can reproduce it before opening an issue over at: https://github.com/ImageMagick/ImageMagick/issues. Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.