{"action":"created","issue":{"url":"https://api.github.com/repos/dahlia/wand/issues/100","labels_url":"https://api.github.com/repos/dahlia/wand/issues/100/labels{/name}","comments_url":"https://api.github.com/repos/dahlia/wand/issues/100/comments","events_url":"https://api.github.com/repos/dahlia/wand/issues/100/events","html_url":"https://github.com/dahlia/wand/issues/100","id":12011653,"number":100,"title":"ImageMagick CLI to Wand compilator","user":{"login":"honzajavorek","id":283441,"avatar_url":"https://avatars.githubusercontent.com/u/283441?v=3","gravatar_id":"","url":"https://api.github.com/users/honzajavorek","html_url":"https://github.com/honzajavorek","followers_url":"https://api.github.com/users/honzajavorek/followers","following_url":"https://api.github.com/users/honzajavorek/following{/other_user}","gists_url":"https://api.github.com/users/honzajavorek/gists{/gist_id}","starred_url":"https://api.github.com/users/honzajavorek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/honzajavorek/subscriptions","organizations_url":"https://api.github.com/users/honzajavorek/orgs","repos_url":"https://api.github.com/users/honzajavorek/repos","events_url":"https://api.github.com/users/honzajavorek/events{/privacy}","received_events_url":"https://api.github.com/users/honzajavorek/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/dahlia/wand/labels/enhance","name":"enhance","color":"e10c02"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/dahlia/wand/milestones/3","html_url":"https://github.com/dahlia/wand/milestones/0.4.0","labels_url":"https://api.github.com/repos/dahlia/wand/milestones/3/labels","id":50696,"number":3,"title":"0.4.0","description":"Implements PIL compatibility layer and improves usability of installation.","creator":{"login":"dahlia","id":12431,"avatar_url":"https://avatars.githubusercontent.com/u/12431?v=3","gravatar_id":"","url":"https://api.github.com/users/dahlia","html_url":"https://github.com/dahlia","followers_url":"https://api.github.com/users/dahlia/followers","following_url":"https://api.github.com/users/dahlia/following{/other_user}","gists_url":"https://api.github.com/users/dahlia/gists{/gist_id}","starred_url":"https://api.github.com/users/dahlia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dahlia/subscriptions","organizations_url":"https://api.github.com/users/dahlia/orgs","repos_url":"https://api.github.com/users/dahlia/repos","events_url":"https://api.github.com/users/dahlia/events{/privacy}","received_events_url":"https://api.github.com/users/dahlia/received_events","type":"User","site_admin":false},"open_issues":9,"closed_issues":2,"state":"open","created_at":"2011-10-28T02:40:07Z","updated_at":"2014-09-06T13:39:54Z","due_on":null,"closed_at":null},"comments":11,"created_at":"2013-03-14T09:54:38Z","updated_at":"2015-04-03T15:16:55Z","closed_at":null,"body":"Just an idea, maybe silly, feel free to close this. Dive into the world of dreams and imagine following tool...\r\n\r\nI have standard CLI command for ImageMagick:\r\n\r\n```bash\r\nconvert test.jpg ( -clone 0 -fill '#00ff00' -colorize 100% ) ( -clone 0 -colorspace gray ) -compose blend -define compose:args=0,100 -composite test.jpg\r\n```\r\n\r\nI can do this:\r\n\r\n```python\r\nfrom wand import cli_compiler\r\n\r\ncmd = '''\r\n    convert {filename}\r\n    ( -clone 0 -fill {color} -colorize 100% )\r\n    ( -clone 0 -colorspace gray )\r\n    -compose blend -define compose:args=0,100\r\n    -composite\r\n    {filename}\r\n'''\r\nprocessor = cli_compiler(cmd)   # pre-compiles the command\r\nprocessor(filename='test.jpg', color='#00ff00')  # does the job\r\n```\r\n\r\n`cli_compiler` would translate the command into Python code calling MagickWand API. It would also support parameters, as shown above. It returns callable, which does the job.\r\n\r\nIs this science-fiction? I think it could be done by PLY or something, though the parser would have to be probably very complex. I don't know IM's \"parameter language\" so well so I could judge it from such point of view right now.\r\n\r\n--------------\r\n\r\nUse cases:\r\n\r\n- I have old code with subprocessing ImageMagick. Having such compiler, I can immediately migrate to Wand.\r\n- I have no further knowledge of ImageMagick and I find a tutorial on the internet how to perform what I need - of course using CLI params and `convert` command. I could just copy-paste it and use such compiler. Job done in 3 minutes!"},"comment":{"url":"https://api.github.com/repos/dahlia/wand/issues/comments/89317061","html_url":"https://github.com/dahlia/wand/issues/100#issuecomment-89317061","issue_url":"https://api.github.com/repos/dahlia/wand/issues/100","id":89317061,"user":{"login":"emcconville","id":84594,"avatar_url":"https://avatars.githubusercontent.com/u/84594?v=3","gravatar_id":"","url":"https://api.github.com/users/emcconville","html_url":"https://github.com/emcconville","followers_url":"https://api.github.com/users/emcconville/followers","following_url":"https://api.github.com/users/emcconville/following{/other_user}","gists_url":"https://api.github.com/users/emcconville/gists{/gist_id}","starred_url":"https://api.github.com/users/emcconville/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/emcconville/subscriptions","organizations_url":"https://api.github.com/users/emcconville/orgs","repos_url":"https://api.github.com/users/emcconville/repos","events_url":"https://api.github.com/users/emcconville/events{/privacy}","received_events_url":"https://api.github.com/users/emcconville/received_events","type":"User","site_admin":false},"created_at":"2015-04-03T15:16:55Z","updated_at":"2015-04-03T15:16:55Z","body":"Rebooting this effort. This enhancement may be growing in complexity. It's ideal to build out a [lexical analyzer](http://en.wikipedia.org/wiki/Lexical_analysis), but hints of ImageMagick 7 [may suggest changes](http://www.imagemagick.org/script/porting.php#cli) in the upstream CLI parser. Also, some IM operators have different context between utility (e.g. the `-format` & `-frame` alter between `identify` and `convert`.) Building a compiler may be a really large effort.\r\n\r\nIf the original request is just to take raw CLI commands, and optional bind parameters feature, then [MagickCommandGenesis](http://www.imagemagick.org/api/mogrify.php#MagickCommandGenesis)  could offer a straight solution. Each ImageMagick utility has it's own CLI parser, which we can \"hand-off\" user commands to. I'm [experimenting with this method](https://github.com/emcconville/wand/blob/issue-100-CLI-compilator/wand/cli.py), and it seems like a valid proposal.\r\n\r\n```python\r\nfrom wand.cli import Parser\r\n\r\ncmd = '''\r\n    convert {filename}\r\n    ( -clone 0 -fill {color} -colorize 100% )\r\n    ( -clone 0 -colorspace gray )\r\n    -compose blend -define compose:args=0,100\r\n    -composite\r\n    {filename}\r\n'''\r\nprocessor = Parser(cmd)\r\nprocessor(filename='test.jpg', color='#00ff00') \r\n```\r\n\r\n**Pros:** Easy to implement & support\r\n**Cons:** ImageMagick hijacks I/O, like stdout & stderr. (although that might be desired behavior)"}}