{"id":13636644,"url":"https://github.com/leafo/magick","last_synced_at":"2025-04-04T23:09:28.929Z","repository":{"id":6599202,"uuid":"7842234","full_name":"leafo/magick","owner":"leafo","description":"Lua bindings to ImageMagick for LuaJIT using FFI","archived":false,"fork":false,"pushed_at":"2024-05-17T12:00:10.000Z","size":244,"stargazers_count":412,"open_issues_count":29,"forks_count":81,"subscribers_count":26,"default_branch":"master","last_synced_at":"2025-03-28T22:13:30.545Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leafo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-01-26T19:14:21.000Z","updated_at":"2025-02-17T01:59:06.000Z","dependencies_parsed_at":"2024-05-01T20:45:14.918Z","dependency_job_id":"d9842210-e0f1-419b-ad4f-7741c04aaa20","html_url":"https://github.com/leafo/magick","commit_stats":{"total_commits":149,"total_committers":9,"mean_commits":"16.555555555555557","dds":0.08053691275167785,"last_synced_commit":"6971fa700c4d392130492a3925344b51c7cc54aa"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafo%2Fmagick","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafo%2Fmagick/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafo%2Fmagick/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafo%2Fmagick/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leafo","download_url":"https://codeload.github.com/leafo/magick/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247261612,"owners_count":20910108,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T00:01:03.666Z","updated_at":"2025-04-04T23:09:28.907Z","avatar_url":"https://github.com/leafo.png","language":"Lua","funding_links":[],"categories":["Libraries","Lua","资源","Resources"],"sub_categories":["Image Manipulation"],"readme":"# magick\n\n![test](https://github.com/leafo/magick/workflows/test/badge.svg)\n\nLua bindings to ImageMagick's\n[MagicWand](http://www.imagemagick.org/script/magick-wand.php) or\nGraphicsMagick's [Wand](http://www.graphicsmagick.org/wand/wand.html) for\nLuaJIT using FFI.\n\n## Installation\n\nYou'll need both LuaJIT (any version) and MagickWand or GraphicsMagickinstalled.\n\n\nOn Ubuntu, to use ImageMagick, you might run:\n\n```bash\n$ sudo apt-get install luajit\n$ sudo apt-get install libmagickwand-dev\n```\n\nYou can install GraphicsMagick in place of, or alongside, ImageMagick:\n\n```bash\n$ sudo apt-get install libgraphicsmagick1-dev\n```\n\nIt's recommended to use LuaRocks to install **magick**.\n\n```bash\n$ sudo apt-get install luarocks\n$ luarocks install magick\n```\n\n## Basic Usage\n\nIf you just need to resize/crop an image, use the `thumb` function. It provides\na shorthand syntax for common operations.\n\n```lua\nlocal magick = require(\"magick\")\nmagick.thumb(\"input.png\", \"100x100\", \"output.png\")\n```\n\nThe second argument to `thumb` is a size string, it can have the following\nkinds of values:\n\n\n```lua\n\"500x300\"       -- Resize image such that the aspect ratio is kept,\n                --  the width does not exceed 500 and the height does\n                --  not exceed 300\n\"500x300!\"      -- Resize image to 500 by 300, ignoring aspect ratio\n\"500x\"          -- Resize width to 500 keep aspect ratio\n\"x300\"          -- Resize height to 300 keep aspect ratio\n\"50%x20%\"       -- Resize width to 50% and height to 20% of original\n\"500x300#\"      -- Resize image to 500 by 300, but crop either top\n                --  or bottom to keep aspect ratio\n\"500x300+10+20\" -- Crop image to 500 by 300 at position 10,20\n```\n\nIf you need more advanced image operations, you'll need to work with the\n`Image` object. Read on.\n\n## Functions\n\nAll functions contained in the table returned by `require(\"magick\")`.\n\n#### `thumb(input_fname, size_str, out_fname=nil)`\n\nLoads and resizes image. Write output to `out_fname` if provided, otherwise a\nstring is returned with the binary data of the resulting image.\n(`input_fname` can optionally be an instance of `Image`)\n\n`size_str` is a described above under `thumb`.\n\n#### `load_image(fname)`\n\nReturn a new `Image` instance, loaded from filename. Returns `nil` and error\nmessage if image could not be loaded.\n\n#### `load_image_from_blob(blob)`\n\nLoads an image from a Lua string containing the binary image data.\n\n## `Image` object\n\nCalling `load_image` or `load_image_from_blob` returns an `Image` object.\n\n\n```lua\nlocal magick = require \"magick\"\n\nlocal img = assert(magick.load_image(\"hello.png\"))\n\nprint(\"width:\", img:get_width(), \"height:\", img:get_height());\n\nimg:resize(200, 200)\nimg:write(\"resized.png\")\n```\n\nImages are automatically freed from memory by LuaJIT's garbage collector, but\nimages can take up a lot of space in memory when loaded so it's recommended to\ncall `destroy` on the image object as soon as possible.\n\n### Using GraphicsMagick\n\nImageMagick and GraphicsMagick implement (mostly) the same interface. By\ndefault the `magick` module will include ImageMagick. You can specify which\nlibrary you use by calling `require` on the module for the appropriate library.\nAt the moment it's impossible to include both libraries into the same process\ndue to collision of function names in the C namespace.\n\nLoad ImageMagick directly:\n\n```lua\nmagick = requrie \"magick.wand\"\nlocal img = magick.load_image(\"some_image.png\")\n```\n\nLoad GraphicsMagick directly:\n\n```lua\nmagick = requrie \"magick.gmwand\"\nlocal img = magick.load_image(\"some_image.png\")\n```\n### Methods\n\n\u003e **Note:** Not all the functionality of the respective image libraries is\n\u003e exposted on the Image interface. Pull requests welcome.\n\nMethods mutate the current image when appropriate. Use `clone` to get an\nindependent copy.\n\n#### `img:resize(w,h, f=\"Lanczos2\", blur=1.0)`\n\nResizes the image, `f` is resize function, see [Filer Types](http://www.imagemagick.org/api/MagickCore/resample_8h.html#a12be80da7313b1cc5a7e1061c0c108ea)\n\n#### `img:adaptive_resize(w,h)`\n\nResizes the image using [adaptive resize](http://imagemagick.org/Usage/resize/#adaptive-resize)\n\n#### `img:crop(w,h, x=0, y=0)`\n\nCrops image to `w`,`h` where the top left is `x`, `y`\n\n#### `img:blur(sigma, radius=0)`\n\nBlurs the image with specified parameters. See [Blur Arguments](http://www.imagemagick.org/Usage/blur/#blur_args)\n\n#### `img:rotate(degrees, r=0, g=0, b)`\n\nRotates the image by specified number of degrees. The image dimensions will\nenlarge to prevent cropping. The triangles on the corners are filled with the\ncolor specified by `r`, `g`, `b`. The color components are specified as\nfloating point numbers from 0 to 1.\n\n#### `img:sharpen(sigma, radius=0)`\n\nSharpens the image with specified parameters. See [Sharpening Images](http://www.imagemagick.org/Usage/blur/#sharpen)\n\n#### `img:resize_and_crop(w,h)`\n\nResizes the image to `w`,`h`. The image will be cropped if necessary to\nmaintain its aspect ratio.\n\n#### `img:get_blob()`\n\nReturns Lua string containing the binary data of the image. The blob is\nformatted the same as the image's current format (eg. PNG, Gif, etc.). Use\n`image:set_format` to change the format.\n\n#### `img:write(fname)`\n\nWrites the image to the specified filename\n\n#### `img:get_width()`\n\nGets the width of the image\n\n#### `img:get_height()`\n\nGets the height of the image\n\n#### `img:get_format()`\n\nGets the current format of image as a file extension like `\"png\"` or `\"bmp\"`.\nUse `image:set_format` to change the format.\n\n#### `img:set_format(format)`\n\nSets the format of the image, takes a file extension like `\"png\"` or `\"bmp\"`\n\n#### `img:get_quality()`\n\nGets the image compression quality.\n\n#### `img:set_quality(quality)`\n\nSets the image compression quality.\n\n#### `img:get_gravity()`\n\nGets the image gravity type.\n\n#### `img:set_gravity(gravity)`\n\nSets the image's gravity type:\n\n`gravity` can be one of the values listed in [data.moon](https://github.com/leafo/magick/blob/master/magick/wand/data.moon#L77)\n\n#### `img:get_option(magick, key)`\n\nReturns all the option names that match the specified pattern associated with a\nimage (e.g `img:get_option(\"webp\", \"lossless\")`)\n\n#### `img:set_option(magick, key, value)`\n\nAssociates one or options with the img (e.g `img:set_option(\"webp\", \"lossless\", \"0\")`)\n\n#### `img:scale(w, h)`\n\nScale the size of an image to the given dimensions.\n\n#### `img:coalesce()`\n\nCoalesces the current image by compositing each frame on the previous frame.\nThis un-optimized animated images to make them suitable for other methods.\n\n#### `img:composite(source, x, y, compose)`\n\nComposite another image onto another at the specified offset `x`, `y`.\n\n`compose` can be one of the values listed in [data.moon](https://github.com/leafo/magick/blob/master/magick/wand/data.moon#L5)\n\n#### `img:strip()`\n\nStrips image of all profiles and comments, useful for removing exif and other data\n\n#### `r,g,b,a = img:get_pixel(x, y)`\n\nGet the r,g,b,a color components of a pixel in the image as doubles from `0` to `1`\n\n#### `img:clone()`\n\nReturns a copy of the image.\n\n#### `img:modulate(brightness=100, saturation=100, hue=100)`\n\nAdjust the brightness, saturation, and hue of the image. See [Modulate Brightness, Saturation, and Hue](http://www.imagemagick.org/Usage/color_mods/#modulate)\n\n#### `img:thumb(size_str)`\n\nMutates the image to be a thumbnail. Uses the same size string format described\nat the top of this README.\n\n#### `img:destroy()`\n\nImmediately frees the memory associated with the image, it is invalid to use\nthe image after calling this method. It is unnecessary to call this method\nnormally as images are tracked by the garbage collector.\n\n# Tests\n\nTests use [Busted](http://olivinelabs.com/busted). Install and execute the\nfollowing command to run tests. You can check the output in\n`spec/output_images/`.\n\n```bash\n$ busted\n```\n\n# Changelog\n\n### 1.6.0 - Tue Feb  2 01:18:06 PM PST 2021\n\n* Support ImageMagick 7\n* Fix memory leak with `coalesce` for ImageMagick\n* Add `sharpen`, `set_quality`, `auto_orient`, `get_colorspace`, `set_colorspace`, `level_image`, `hald_clut` for GraphicsMagick\n* Throw error if size string can not be parsed in `thumb`, handle case when source size is missing, more specs for `thumb`\n* Update test suite to GitHub actions, remove TravisCI\n  * Test suite runs for LuaJIT beta and OpenResty's LuaJIT fork\n  * Currently runs on Ubuntu: ImageMagick 6.9.10, GraphicsMagick 1.3.35, Arch Linux: ImageMagick 7.0.10.61, GraphicsMagick 1.3.36\n  * Fix broken spec for `modulate`\n\n### 1.5.0 - Tue Jun 20 13:33:41 PDT 2017\n\n* Add `get_depth` and `set_depth` to GraphicsMagick \u0026 ImageMagick\n\n### 1.4.0 - Tue Jun  6 22:54:12 PDT 2017\n\n* Add `reset_page` to GraphicsMagick\n* Add `get_format` and `set_format` to GraphicsMagick\n\n### 1.3.0 - Wed Mar  8 09:49:31 PST 2017\n\n* Add modulate (@granpc)\n* Add more methods to graphics magick: composite, clone, blur (@granpc)\n* Add reset page to imagemagick wand (@thierrylamarre)\n* Clone method is uses the clone function provided by image magick, garbage collects new image\n* Add `thumb` method on the image class\n\n### 1.2.0 - Tue Jul 12 21:10:23 PDT 2016\n\n* Add preliminary GraphicsMagick support\n* Fix bug with gravity getter/setter (@ram-nadella)\n* Add additional wand method: https://github.com/leafo/magick/pull/32 (@sergeyfedotov)\n\n### 1.1.0 - Thu Oct 22 05:11:41 UTC 2015\n\n* add automatic memory management with `ffi.gc`\n* fix some string memory leaks when getting type and options of image\n* add `coalesce`, `rotate` methods to image\n* use `pkg-config` instead of `MagickWand-config` to query library\n* all include paths provided by config are searched instead of first\n\n# Contact\n\nAuthor: Leaf Corcoran (leafo) ([@moonscript](http://twitter.com/moonscript))  \nEmail: leafot@gmail.com  \nHomepage: \u003chttp://leafo.net\u003e  \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleafo%2Fmagick","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleafo%2Fmagick","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleafo%2Fmagick/lists"}