-
Notifications
You must be signed in to change notification settings - Fork 199
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
ImageMagick CLI to Wand compilator #100
Comments
👍 |
It’s really a brilliant idea for me, though it seems hard to be completely implemented, because there are still a lot of lacking features for Wand when it compares to ImageMagick. Plus, I think the compiler should be possible to generate actual Python codes. It help users who don’t want to maintain command strings (which cannot be easily composed) to migrate their code to pure Wand API calls. |
👍 |
Well I wrote a simple compiler (in PLY) of custom query language into SQL (code to code) and later on I changed it so it constructs directly an object of dynamic select clause from SQLAlchemy (code to complex set of objects). It was not harder to write one or another, so I assume this to be just an implementation detail. I agree that for purposes of Wand, generation of code would be probably more helpful, it makes sense to me. So the only stopper here is that Wand does not have complete API support? Well, we could implement what is already available and just raise |
I think it would be released in 0.4.0 if we start working on this. |
I could help with writing the compiler. But first I suggest to start from designing the API of such feature. If it's supposed to be code generator, it could be available as standalone script, a tool for developers. |
It could consist of two primitives and rest facades:
|
👍 Although I do not know Python |
Oh '''
convert {filename}
( -clone 0 -fill {color} -colorize 100% )
( -clone 0 -colorspace gray )
-compose blend -define compose:args=0,100
-composite
{filename}
''' |
I think the reason why Armin made Jinja without any parser generators/combinators is that he want to make the syntax customizable. For example, you can use |
Rebooting this effort. This enhancement may be growing in complexity. It's ideal to build out a lexical analyzer, but hints of ImageMagick 7 may suggest changes in the upstream CLI parser. Also, some IM operators have different context between utility (e.g. the If the original request is just to take raw CLI commands, and optional bind parameters feature, then 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, and it seems like a valid proposal. from wand.cli import Parser
cmd = '''
convert {filename}
( -clone 0 -fill {color} -colorize 100% )
( -clone 0 -colorspace gray )
-compose blend -define compose:args=0,100
-composite
{filename}
'''
processor = Parser(cmd)
processor(filename='test.jpg', color='#00ff00') Pros: Easy to implement & support |
There would be two purposes as @honzajavorek said:
The solution proposed by @emcconville seems to solve only the former one. Although it does not mean I disagree with @emcconville. If the latter purpose does not that matter it could be a valid solution. |
I do not do much with ImageMagick these days, but from those two use cases I see the second as more "important" nice-to-have feature, because:
From my POV enabling |
Just an idea, maybe silly, feel free to close this. Dive into the world of dreams and imagine following tool...
I have standard CLI command for ImageMagick:
convert test.jpg ( -clone 0 -fill '#00ff00' -colorize 100% ) ( -clone 0 -colorspace gray ) -compose blend -define compose:args=0,100 -composite test.jpg
I can do this:
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.Is 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.
Use cases:
convert
command. I could just copy-paste it and use such compiler. Job done in 3 minutes!The text was updated successfully, but these errors were encountered: