• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

isage/lua-imagick: Lua pure-c bindings to ImageMagick

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

isage/lua-imagick

开源软件地址(OpenSource Url):

https://github.com/isage/lua-imagick

开源编程语言(OpenSource Language):

Lua 46.9%

开源软件介绍(OpenSource Introduction):

Lua IMagick Build Status

Pure-C lua bindings to ImageMagick

Why?

Because existing FFI-based bindings are hackish and buggy, duh.

Table of Contents

FAQ

  1. Q) Will this work with openresty/nginx-lua?
    A) Yes. But remember, that IM operations are blocking.
  2. Q) Is this production ready?
    A) Yes, we're using it for couple of months now without problems.
  3. Q) Is this feature-complete?
    A) Hell no. There's lot of uncovered IM api. I've implemented only needed for me api for now.
  4. Q) How do i properly resize animated gif?
    A) Firstly, coalesce() it, then resize as usual, then optimize() it back. You really should cache coalesce()'ed image if you resizing it frequently.

Requirements

  • ImageMagick developer headers (>=6.8.8.3)
  • Lua (5.1/5.2) or LuaJit
  • Cmake 2.8.12 or later
  • Working C compiler

You can get fresh IM and cmake for ubuntu 12.04/14.04 here

Installation

As easy as

mkdir build
cd build
cmake ..
make
make install

You can also use make unittest after make to run tests.
By default module compiles with support for luajit
For other Lua interpreters see cmake options.

Usage

Synopsis

local magick = require "imagick"

local img = magick.open("filename.jpg")
img:set_gravity(magick.gravity["NorthGravity"])
img:smart_resize("100x100^")
img:extent(100, 100)
img:set_quality(90)
img:strip()
img:write("out.jpg")

Enumerations

imagick.gravity

Gravity values
See here
Example

local magick = require "imagick"
print(magick.gravity["WestGravity"])

imagick.interlace

Interlace scheme values
See here
Example

local magick = require "imagick"
print(magick.interlace["JPEGInterlace"])

imagick.colorspace

Colorspace values
See here

Example

local magick = require "imagick"
print(magick.colorspace["YUVColorspace"])

imagick.filters

Scale filters
See here

Example

local magick = require "imagick"
print(magick.filters["LanczosSharpFilter"])

imagick.composite_op

Composite operations
See here

Example

local magick = require "imagick"
local img = magick.open("input.jpg")
local logo = magick.open("logo.jpg")
img:set_compose( magick.composite_op["CopyCompositeOp"] )
img:composite(logo, 0, 0)
img:write("out.jpg")

imagick.font_style

Font styles

  • UndefinedStyle
  • NormalStyle
  • ItalicStyle
  • ObliqueStyle
  • AnyStyle

imagick.text_align

Font align

  • UndefinedAlign
  • LeftAlign
  • CenterAlign
  • RightAlign

imagick.channel

Color channels
See here

imagick.distort_method

methods for MagickDistortImage
See here

Color channels
See here

imagick functions

<image>image, <string>error = imagick.open(<string> filepath)

Opens image from given filepath or image definition

Example

local img = magick.open("input.jpg")  -- open jpg file

<image>image, <string>error = imagick.open_blob(<string> data)

Open image from data blob


<image>image, <string>error = imagick.open_pseudo(<int> width, <int> height, <string> definition)

Create image from pseudo-image definition. See here


imagick image functions

<void> img:destroy()

Manually free all allocated for image memory.
Use with caution. Never call to any image methods afterwards.


<int>width = img:width()

Get image width in pixels


<int>height = img:height()

Get image height in pixels


<int>count = img:count()

Get number of images inside an image (e.g. frames in GIF or pages in PDF)


<image>image = img:clone()

Clone image with all current settings/values


<bool>status, <string>error = img:write(<string> filename)

Write image to file
This outputs only first frame


<bool>status, <string>error = img:write_all(<string> filename, <bool> join)

Write all image frames to file
If join is false this will create sequentaly numbered file for each image frame If join is true this will create one file with all frames (this demends on image format, works with gif, for example)


<string>data, <int>lenght = img:blob()

Return raw image data as string


<string>format = img:get_format()

Get image format ("JPEG"/"GIF"/"PNG"/etc.)


<bool>result, <string>error = img:set_format(<string> format)

Set image format ("JPEG"/"GIF"/"PNG"/etc.)


<int>quality = img:get_quality()

Get image compression quality (0-100)


<bool>status, <string>error = img:set_quality(<int> quality)

Set image compression quality (0-100)


<int>gravity = img:get_gravity()

Get current image gravity


<bool>status, <string>error = img:set_gravity(<int> gravity)

Set image gravity (See imagick.gravity enum)


<int>scheme = img:get_interlace()

Get current image interlace scheme


<bool>status, <string>error = img:set_interlace(<int> scheme)

Set image interlace sheme (See imagick.interlace enum)
e.g. for Progressive JPEG set it to JPEGInterlace


<string>value = img:get_option(<string> name)

Get imagemagick option for image


<bool>status, <string>error = img:set_option(<string> name, <string>value)

Set imagemagick option for image


<string>value = img:get_artifact(<string> name)

Get imagemagick artifact for image. See here


<bool>status, <string>error = img:set_artifact(<string> name, <string>value)

Set imagemagick artifact for image


<string>color = img:get_bg_color()

Get image background color
Returns comma-separated color values.


<bool>status, <string>error = img:set_bg_color(<string> color)

Set image background color (html hex notation or comma-separated)


<int>colorspace = img:get_colorspace()

Get image colorspace (See imagick.colorspace enum)


<bool>status, <string>error = img:set_colorspace(<colorspace> colorspace)

Set image colorspace (See imagick.colorspace enum)


<bool>alpha = img:has_alphachannel()

Returns true if image has alpha-channel


<bool>icc = img:has_icc_profile()

Returns true if image has embedded icc profile


<string>data = img:get_icc_profile()

Returns image icc profile as blob


<bool>status, <string>error = img:set_icc_profile(<string> blob)

Set (and convert image to) image icc profile from blob


<bool>status, <string>error = img:set_compose(<int> compose)

Set image composite operator (See imagick.composite_op)


<bool>status, <string>error = img:set_font(<string> path)

Set font to use in annotate, full path to font file


<bool>status, <string>error = img:set_font_family(<string> family)

Set font to use in annotate, font family string


<bool>status, <string>error = img:set_font_size(<int> size)

Set font size to use in annotate


<bool>status, <string>error = img:set_font_style(<int> style)

Set font style to use in annotate (See imagick.font_style enum)


<bool>status, <string>error = img:set_font_weight(<int> weight)

Set font weight to use in annotate


<bool>status, <string>error = img:set_font_align(<int> align)

Set font align to use in annotate (See imagick.font_align enum)


<bool>status, <string>error = img:annotate(<string> color, <string> text, <int> x, <int> y, <int> angle)

Annotate image


<bool>status, <string>error = img:set_mask(<image> mask)

Set image mask for compositing operations You can set it to nil to reset


<bool>status, <string>error = img:coalesce()

Coalesce (rebuild) all image frames


<bool>status, <string>error = img:optimize()

Optimise all image frames


<bool>status, <string>error = img:deconstruct()

Deconstruct all image frames (MagickDeconstructImages() )


<bool>status, <string>error = img:strip()

Strip exif data and profiles from image


<bool>status, <string>error = img:swirl(<int>degrees)

Apply swirl filter


<bool>status, <string>error = img:oilpaint(<int> radius)

Apply oilpaint filter


<bool>status, <string>error = img:rotate(<string>color, <double> angle)

Rotate image on angle filling empty space with color


<bool>status, <string>error = img:modulate(<double> brightness, <double> saturation, <double> hue)

Modify brightness, saturation, and hue of an image


<bool>status, <string>error = img:blur(<double> sigma, <double> radius)

Blur image


<bool>status, <string>error = img:flip()

Creates a vertical mirror image by reflecting the pixels around the central x-axis.


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap