Gimp from command line - linux

I used Gimp to export a PNG to another without color values from transparent pixels. Is there ay way to do the same from the command line? I'm going to use this script from a php.
The option in Gimp UI is "Save color values from transparent pixels" unchecked.
Best,

Rather than trying to script a huge, interactive GUI program like the Gimp, how about just using a simple command line image tool like ImageMagick's convert. Here's the example that does exactly this from their documentation:
convert moon.png -background HotPink -alpha Background moon_hotpink.png

Related

How to crop a SVG image to the bounding box of the vector grafics elements

I have a SVG image here which is generated with 'empty space', i.e. only in the top-left corner is image content, whereas the rest is blank. I think it should be trivially possible to have an automated way to crop the image size to the bounding box of the objects - at least for some svg tooling like rsvg. However I am unable to find the 'command line trick' for this, etc.
I would like to do this on the command line (i.e. as part of a build script)
In principle I would be interested in a solution to the same problem but for pixel-based formats such as PNG as well.
rsvg does not have command line utilities for this problem, but Inkscape in its non-GUI mode has:
inkscape -o cropped.svg -D source.svg
will crop the file to the bounding box of all objects of the document. See the man page for a full documentation of the inkscape command line options. Especially note the --shell mode for batch processing multiple images.
For pixel-based formats there is the imagemagick -trim option:
convert source.png -trim +repage cropped.png

Is it possible to make Inkscape autotrace PNG to SVG, but from the command line?

I want to automate "raster to vector" conversions. PNG to SVG. (most Qs here on SO are the other way around)
I have tried the old command line tool autotrace on Linux, but I could not get it to run. I've tried to install a package, and to compile it from the source. Nope.
Then I've realised that Inkscape has "autotrace" now integrated in its codebase. I'd like to convert simple sketches from PNG to SVG.
And I want to do this in a Bash for-loop , with different autotrace settings (number of passes; ignore Speckles with max X pixels width) etc.
I've tried the "action" command-line option
inkscape --without-gui --actions="file-open:my.png"
and this brings up the small "png bitmap image import" dialog, waiting for me to confirm.
Also I've tried the verb command line option
inkscape --with-gui --verb="FileImport:my.png"
and this opens the large "Select file to import" dialog (ignoring my --verb argument)
At this point I gave up.
I want Inkscape to import a PNG picture, autotrace it with some settings, save it as SVG. Perhaps, beofre saving, duplicate the traced layer, lock the imported background layer, rename the layers from path-12345 to "tracesettings-x-y-z" etc.
(my final goal is to permute the tracing settings, to find good ones for my use-case, but that's not the focus of this question)
Inkscape is using potrace and autotrace to trace bitmap images into vector formats such as SVG and PDF.
Let's assume you have an image: foo.png that you want to trace to SVG using potrace:
First, you need to convert your image to a bitmap format (BMP).
Invoke the potrace command
# I am using ImageMagick convert command to convert PNG to BMP
convert foo.png foo.bmp
# Invoke potrace command with SVG backend
potrace -b svg foo.bmp
The result will be: foo.svg.

How to get a Hex Color Code from a solid-color image for a script?

I was writing a script to change my background on my Linux Machine to a random image from a set of images that contain only solid colors. What I would like to do is expand this script to also theme certain applications (mostly terminal ones) accordingly, at the very least to change the text color, possibly switch from dark to light background, etc. I was wondering what options I have to get the Hex Code for the color in the image. Is there something in bash I can do this with? Would I need to write a program in a more robust language and have the hex-code be the output? Is there a better way of doing this entirely? My searching thus far has been a bit inconclusive.
I would highly recommend to use ImageMagick for this task. The documentation mentions how to extract data from an image.
From "Extracting the average colour":
The average color of an image can be found very quickly by using "-scale" to reduce an image to a single pixel. Here for example is the average color of the built-in "rose:" image. I output the color using the FX Escape Format which
returns a color string that can be used directly IM without change.
user#laptop:~$ convert rose: -scale 1x1\! -format '%[pixel:s]\n' info:-
Will output: srgb(146,89,80)
In your case, replace rose: with an image file of yours, like foo.png.
If you want the output directly in hex notation, use this:
convert rose: -scale 1x1\! -format '%[pixel:s]\n' info:- | awk -F '[(,)]' '{printf("#%x%x%x\n",$2,$3,$4)}'

Create an Image either using Magick Wand or ImageMagick on Python 3

There's not enough information on Internet about imagemagick and magick wand on Python 3. I need to create a lot of images using Python 3, creating the images with a background color or a background image.
When I get the image with the background I want, then I need to add text with a font of my preference on It, I think I can solve the problem of the font, but how to add the "string" in the image?
After that, I want to save the image with a "name".
I have installed Magick wand and Image Magick on Python 3, but the documentation is in a language that I really don't understand. Do I need to install something else?
If you're able to help me, it would be great. Thank you!
You can achieve these using Wand.
Creating the images with a background color or a background image
Add text with a font
Save the image with a “name”

Is there a way to get pixel color in Inkscape using command-line or within extension

So lets say there is some SVG file which might have some bitmap objects as well. What i need is some way to detrmine the color of pixel with coordinates X, Y. Basicly same what "dropper tool" does but calling it from command line or from inkscape python extension.
You can use the inkscape binary to export an image, and then use a scripting language (such as PHP) to do the sampling:
inkscape --without-gui --export-png=myfile.png --export-dpi=100 myfile.svg
If you don't set the DPI it defaults to 90.
I imagine you can also do this in a Python extension, but I can't help there - but there's probably docs for that.

Resources