How to create a transparent image with GraphicsMagick CLI? - graphicsmagick

I'm coming up empty handed while trying to find out how to modify the opacity of an image using the GraphicsMagick CLI. I'm simply trying to input a standard image and convert it to the corresponding image with a reduced opacity. I'm running GraphicsMagick 1.3.14. Using ImageMagick, I can issue the command:
convert input.png -alpha set -channel a -evaluate set 50% +channel output.png
However, the -alpha option (among others) is unrecognized as a valid GM convert option (convert option reference here). Any help would be greatly appreciated.

This question was cross-posted on SuperUser, as I later thought SuperUser might be the more appropriate outlet. To quote Bob Friesenhahn:
The equivalent in GraphicsMagick is
gm convert input.png -operator Opacity Multiply 0.5 output.png
or
gm convert input.png -operator Opacity Assign 50% output.png
depending on what you really want to do (modulate or assign).
You should add -matte prior to -operator if you don't know if the image already has an active opacity channel.
Bob

Related

FontForge: Count of Defined Glyphs

I'm fairly new to FontForge, and I just want to merge two fonts for my specific usage.
I know how to merge two fonts from this question and I'm aware of TTF, ... 65535 lookup limits, so I'm trying to Detach & Remove Glyphs... for some glyph ranges, and for this:
I need to know how many glyph is defined, so I can decide which range to detach and remove. It seems fairly simple info, but I can not find where it is shown.
is there any menu or macro to show the current number of defined glyphs in FontForge?
I was looking for the same info. This will give you the number of defined glyphs fairly quickly:
fontforge -lang=ff \
-c 'Open($1); SelectWorthOutputting(); Print($selection)' "$FONTFILE" \
2>/dev/null |tr -d '][' |tr , '\n' |grep -c 1
The SelectWorthOutputting() function fills an array with ones for each defined glyph, so we can print this out and filter it to get the count.
I think found an answer, however it may not be the best approach. as FontForge saves projects in plain text, we can search for StartChar: keywords in the saved project file (project_name.sfd), which each section started by a StartChar: defines one glyphs in the font project. so if we count them we may know how many glyphs has been defined in the font file, for example, in bash the command:
grep -E "^StartChar\:" project_name.sfd | wc -l
would count them for us, and then we may know how many glyphs has been define so far.
This question pops up as first Google hit, so I'll just place this for posterity, but the proper code answer is from #Jerry Penner.
It's also possible from the program GUI to obtain the info in a quick dirty way:
Reduce the number of displayed glyphs via Encoding > Compact menu
Select the last glyph in your font
At the top right below the menu will be displayed the glyph "number" starting from 0 (so in below picture example the total count is 270).
Note: the number displayed is for the current compact view, not the actual glyph number in the font.

Overlay images and set transparency R

I have two images and I want to overlay one on top of the other such that the top layer is transparent and allows the features in the below layer to show to some extent.
I am searching for this functionality within magic and imager packages but can't seem to get it done. Found a good example at this link but it seems to be using some geographical packages (raster formatting) but the end result is what I want.
Image 1:
Image 2
Desired Result
With ImageMagick you can start with "input1.png" and overlay "input2.png" with a particular amount of transparency. This command in *nix shell format shows the basics...
magick input1.png \
\( input2.png -channel A -evaluate multiply 0.5 +channel \) \
-gravity center -composite result.png
First that reads in the base image. Then inside the parentheses it reads in the overlay image and reduces its alpha channel opacity to 50% with "-evaluate multiply 0.5". Then it composites the semi-transparent overlay onto the base image.
In that command the overlay will be centered. Setting the "-gravity ..." and specifying a horizontal and vertical offset with "-geometry +H+V" just before the composite allows you place the overlay anywhere you like on the base image.
To use this command from a Windows command line, the backslashes that escape the parentheses "\(...\)" should be removed "(...)", and the continued-line backslashes "\" need to be changed to carets "^".

What is the correct index position of the Convert command's options of GraphicsMagick

I am confused about the covert command of GraphicsMagick.
According to the documentation (http://www.graphicsmagick.org/convert.html), the synopsis of convert command is:
convert [ options ... ] input_file output_file
According to the above synopsis, I can execute the convert command in the following way:
Example 1:
gm convert -strip -scale x400 inputFile.jpg outputFile.jpg
The above command is executed successfully. Now, I ran the the same command with different index position of the options.
Example 2:
gm convert inputFile.jpg -strip -scale x400 outputFile.jpg
The above example executed successfully. The above example's index position of the options are different, does not match against the synopsis.
My question is, which example is correct?
I fear the answer is partly philosophical, partly folklore, partly opinion and partly flexibility of GraphicsMagick and partly rigidity of manpages. Let me explain...
To understand the answer, you need to differentiate between settings and operators. #KurtPfeifle did a great job here which, for the sake of completeness, I will summarise as follows:
Some parameters are settings - they set and retain their value till the end of the command or till changed. For example, -size sets the size of all canvases created after it is set on the commandline. Until the point it is first set, the default canvas size is 1x1, after it is set it remains till the end of the command.
Some parameters are operators - they generally perform some image processing, such as thresholding or converting to greyscale. These ones operate on all images currently in the image list.
Maybe an example will help. First, we use the -size setting:
gm convert -background none xc:red -size 5x5 xc:lime xc:blue -size 10x10 xc:magenta +append setting.png
Initially, the default size was 1x1, so the red canvas comes out at 1x1. Then I changed the setting and it remained at 5x5 for the lime and blue canvases till I changed it to 10x10 for the magenta one. Those were settings and they set things up for the images yet to come.
Now, I do a similar thing with the -colorspace operator:
gm convert xc:red xc:lime xc:blue -colorspace gray +append operator.png
And you see that the -colorspace operator has changed all the images that were already in the image list, i.e. they process images that have previously been added to the list.
If you like, you could simplify things and say "settings apply to all that is to come, and operators apply to all that has gone". Although I am sure there are counter-examples.
The order of the commandline options was rationalised a few years back and GraphicsMagick permits some flexibility to retain some backward compatibility. That is probably the best explanation of your actual question.
So, in general, you should declare settings as soon as posssible on the commandline and apply operators at the point that makes most sense depending on what images are currently in your list.
Another reason is that it would be very cumbersome, to the point of unintelligibility, if all the GraphicsMagick combinations and permutations were put in a conventional manpage. Can you imagine:
gm convert [[[operators|settings]|[settings|operators]] image] [[settings|operators]|[operators]] ...

Using netbeans digitalclock sample

I am a Java beginner with a question about the operation of the Digitalclock.java example in Netbeans 8.0.2
I want to alter the display to show only Hours and Minutes and change the color. I have found within the code a way to eliminate the display of the Seconds digits and change the color. What I can't do is get rid of the ":" or center the display.
1) Where is the ":" being generated from?
2) How would I center the display?
Thank you,
The colon ":" in this case is not an actual character rather it is being generated by using multiple instances of the java circle class and can be found in line 114 - 117 of the DigitalClock.java file. Centering the the new four digit clock can be accomplished by changing the clock.setLayoutX at line 78. – Six just now edit

How to convert all color code #XXYYZZ to shorter 3 character version #XYZ of whole css file?

How to convert all color code #XXYYZZ to shorter 3 character version #XYZ of whole css file?
You can convert to the shorter 3-character version only colors expressed this way: #RRGGBB where the first and the second characters are the same, the third and fourth characters are the same and the fifth and sixth characters are the same.
So: #CC00DD can be shortened to #C0D while #CC01DD cannot.
A quick way to shorten all the possible colors in a CSS file is to open the file with an editor supporting regular expressions (for example kwrite or kate on linux) and replace (ignoring case) the following regular expression:
#([0-9A-F])\1([0-9A-F])\2([0-9A-F])\3
with this substitution text:
#\1\2\3
Tested with kate.
Otherwise you can use this tool where, if you only need to compress color codes, you can uncheck all the options except the "Compress color codes where possible".
If you are just interested in minimizing the download size for your CSS file, you might use one of the many CSS compressors available (such as this one). And be sure to do the same with your javascript files while you are at it.
You can only shorten CSS colour codes to a 3 character version if they take the form
#XXYYZZ
Then they can be abbreviated
#XYZ
There are only 216 different codes which meet this requirement.

Resources