Invert PNG graphics file with a non-interactive command - drupal

I'm using DruTex, which is a Drupal module to embed Latex equations. The context of the equation is marked, and a Latex interpreter will generate a PNG file:
dvipng -o [IMG_FILE] -D [DPI] -T tight [TMP_DIR]/[HASH].dvi
The dvipng utility is used to generate a PNG from Latex's DVI file. That's good so far, but I could need black background and white foreground for these equations, since otherwise they are hard to read, because they appear in a dark-themed way.
convert (from Imagemagick) doesn't have an -invert flag. Neither does dvipng. So is there a way to invert a png file? I can add something to that routine like:
batch_invert -input [IMG_FILE] -out [IMG_FILE]
However I do not know how I can implement that.

convert has a -negate option that works.
Example:
convert -negate input.png output.png

Related

ZSH vi normal mode to move around printed text

Can I use zsh vi normal mode to move around previous commands output or the printed text in the shell to copy/yank it ?
For example in the screenshot below. I want to move to the output of ls to copy something. When I press j/k zsh cycle my command history but doesn't move up to the printed text. j/k move one line down/up only when I have multiple line command that I'm currently writing but haven't executed yet.
To the best of my knowledge, the ability to access the output of commands interactively is the domain of your terminal (-emulator), not the shell. You would use commands like sed, awk, grep, possibly in a pipe, to access, manipulate and use output you know in advance is the part you are interested in.
To access the output with keyboard shortcuts/command-keys, I suggest using the like of tmux - it allows to copy/yank from the whole terminal display as if it was a text-file in an editor.

Color code of ls function

For an exercice I try to code the ls function.
I'm copying the -G option.
This option will color the name of the file depending of the type.
Until now, I understood than :
- Symbolic link are in magenta
- directory is in cyan
Does any one know which are the other colors used and for what kind of file ?
I'm also looking for the background color.
Kind regards
I showed a script in How to remove dir background in ls -color output which colorizes the output of dircolors -p (and would be useful in this question, since it preserves the comments which explain what's being colored).
The colors used by ls are determined by the LS_COLORS environment variable; or else by a builtin database. The environment variable LS_COLORS is normally set by evaluating the output of dircolors; see man dircolors for details. Use dircolors -p | less to see the current values.

How to colorize a black-transparent PNG icon with ImageMagick

How do I a colorize a black PNG image that has a transparent background using ImageMagick?
Use case:
You have several PNG images like this:
And I want to colorize them like this:
I want to use ImageMagick's convert command, allowing for scripting to process hundreds of icons at a time.
You can use one of the following commands:
$ convert input.png +level-colors "red", output.png
$ convert input.png +level-colors "rgb(255,0,0)", output.png
$ convert input.png +level-colors "#ff0000", output.png
Note that the , character is important here. On the left side of the , character we tell convert which color should replace black and on right side what color should replace white. Therefore nothing should be given after the , character.
Source
... how do I colorize black & transparent PNG images [...] to colorize them like this [...] using ImageMagick
The -fill <COLOR> option works fantastic for this purpose. You can replace "#1bbfc9" with a human-readable name (e.g. "red") or an HTML color code.
convert target-black.png -fill "#1bbfc9" -colorize 100 target-blue.png
... allowing to script and process hundreds of icons at a time
Using the find command, you can recurse hundreds.
Warning: This will replace the originals.
find path/to/files -iname '*.png' -exec convert "{}" -fill "#1bbfc9" -colorize 100 "{}" \;
With ImageMagick, you can process a whole folder of images at one time with mogrify rather than convert if you want all the same color. Create a new output directory to hold the colorized files. Then cd to the folder holding your images.
cd path_to/image_folder
mogrify -format png -path path_to/new_folder -fill "cyan" -colorize 100 *.png
Where replace path_to with your actual path.
You may use color names, hex colors or rgb(...) colors in the fill command, but enclose them in quotes on Linux/Mac OSX. Quotes are not needed for Windows, but should not cause any issues if double quotes.
See mogrify

(t)csh: how to "source" a gzip compressed text file?

I am looking for a Unix command that enables to "source" the text in a gzip compressed text file.
If my explanation is not clear enough, I mean to a command that first unzips the file and then runs the original command on it, like zgrep, zcat, zless, etc. do
Thanks!
Elaborating shellter's approach, you could use
eval `gunzip -c file2source.gz|tr \\n \;`
for simple scripts. (I say simple because the command lines in the file are concatenated into one line.)
Other than that,
to unzip into a real file, and source that,
seems to be the only way.

unix diff to file

I'm having a little trouble getting the output of diff to write to file. I have a new and old version of a .strings file and I want to be able to write the diff between these two files to a .strings.diff file.
Here's where I am right now:
diff -u -a -B $PROJECT_DIR/new/Localizable.strings $PROJECT_DIR/old/Localizable.strings >> $PROJECT_DIR/diff/Localizable.strings.diff
fgrep + $PROJECT_DIR/diff/Localizable.strings.diff > $PROJECT_DIR/diff/Localizable.txt
The result of the diff command writes to Localizable.strings.diff without any issues, but Localizable.strings.diff appears to be a binary file. Is there any way to output the diff to a UTF-8 encoded file instead?
Note that I'm trying to just get the additions using fgrep in my second command. If there's an easier way to do this, please let me know.
Thanks,
Sean
First, you probably need to identify the encoding of the Localizable.strings files. This might be done in a manner described by How to find encoding of a file in Unix via script(s), for example.
Then probably you need to convert the Localizable.strings file to UTF-8 with a tool like iconv using commands something like:
iconv -f x -t UTF-8 $PROJECT_DIR/new/Localizable.strings >Localizable.strings.new.utf8
iconv -f x -t UTF-8 $PROJECT_DIR/old/Localizable.strings >Localizable.strings.old.utf8
Where x is the actual encoding in a form recognized by iconv. You can use iconv --list to show all the encodings it knows about.
Then, you probably need to diff without having to use -a.
diff -u -B Localizable.strings.old.utf8 Localizable.strings.new.utf8 >Localizable.strings.diff.utf8

Resources