How do I draw with inverted color in graphicsmagick? - graphicsmagick

I use graphicsmagick to add text to photos; but I'm having problems selecting the proper color for my text.
With graphicsmagick I can use a command such as this
convert -fill yellow -draw "... text ..." ...
to write yellow text on an image.
Is there a way to write with color inversion instead? What I mean is: Where the underlying picture is black, I want the text to be white; where the underlying picture is white, I want the text to be black; where the underlying picture is a certain color, I want the text to be in its complement color.
EDIT
Please note that "No, it can't be done" is a perfectly good answer to this question if what I want is impossible.

You can use -compose Difference to overlay your desired text:
Original:
Then create a text gif.:
convert -background transparent -fill yellow label:Rose label_white.gif
Then compose them together using difference:
composite -compose Difference -gravity North label_white.gif rose: compose_diff.gif
You can find more compositing info here.

Related

Is this possible with mix-blend-mode?

I'm want the following colors, white background, black letters, purple square appearing behind the text and white text within the square (when overlapping).
I'm trying to achieve this with mix-blend-mode and filter invert but this is the closest I can get.

Does Background Color Without Text Matter?

Regarding color contrast:
In this example, do I need to be careful of the blue background even though there is no copy directly on top of it? I.e. do I only need to be concerned with background color when there is copy on top of it, and I could hide the element with the background color from screen readers without causing an issue?
And in this one, do I need to be careful of the contrast between the light blue background and the button or am I only concerned with the contrast between the copy and the button? (I know the image is blurry. It's just an example.)
Both examples are fine as they are.
There are two things that are applicable here.
The first is contrast between text and the background for that text - you must have a contrast ratio of 4.5:1 for normal text and 3:1 for large text / bold text to be WCAG AA compliant. In the first example it is essentially black on white so it will pass easily.
The second is for controls. Buttons, inputs etc. should have a contrast ratio with their background of 3:1 minimum, no matter what state they are in (so if your above button turned white with black text on hover it probably wouldn't pass). In your second example your button is black on light blue so it certainly passes this also.
Also worth noting is that text within controls (your button) has the same 4.5:1 contrast requirement. Yet again white on black passes easily so you are fine.
Just check the contrast (almost certainly fine) on the red button with white text, reds and oranges can be deceiving in their contrast ratios (but as it is quite a dark red I am 99% sure you are fine just by looking at it).
For clarity your blue background in the first one could be 1% darker than the white box and it would be fine as it is not an interactive control that it surrounds.

GraphicsMagick: How to move image content from left side to center

Situation: I have a PNG image created from a SVG by exporting the image from Internet Explorer. Although the main motive in SVG is located in the center, in the exported PNG it appears in the left half. I used IE for the export because the quality of the PNG image is far better than results obtained by other tools.
Problem: I would like to use GraphicsMagick to shift the picture to the center. I could use crop to cut off the extra empty space on the right hand side, but I don't know how to add empty transparent space on the right.
SVG image:
PNG image:
What command should I use in Graphicsmagick to transform the PNG to a PNG with the logo located in the center while preserving the original square dimensions (500x500) of the image? (I was not satisfied with quality of PNG generated by GraphicsMagick from SVG directly)
This should do the trick:
gm convert logo.svg -trim -gravity center -extent 500x500 result.png
Setting the colour for the -extent makes it clearer what is happening:
gm convert logo.svg -trim -gravity center -background pink -extent 500x500 result.png

Blend text as white over image

I am trying to reproduce the effect of this page : http://www.saramarandi.com/ .
I want that when an image is over a black text, the text blends into white.
I have tried combinations of mix-blend-mode, color, text-clip without any success.

Stop QLabel text blending with background colour

In short
I'm trying to get the text in my QLabel to paint as if it were over a black background, ignoring the real background colour.
In depth
I have a QLabel in a green coloured widget, the text is anti-aliased and white, the anti-aliasing softens the edges of the text by blending with the green background colour.
Hardware detects the exact green colour and uses it like a green screen to display some techno-wizardry without also drawing over my software overlay, it makes the background look black.
The anti-aliased text has a fuzzy green halo where it has slightly changed the green colour and hardware doesn't overwrite it.
I want the text to be draw as if it were over a black background
What I've tried
I have tried using a black opaque QGraphicsDropShadowEffect to be drawn under the text, thus giving the text a black background to draw on, this led to a bigger green halo around the text.
I have tried setting various QBrushes in the label's QPalette for the Qt::WindowText and Qt::Base ColorRoles.
I have re-implemented the paintEvent and I am trying to use style()->drawItemText(... ) to avoid re-implementing all the helpful alignment code.
I have tried intercepting the QStyleOpt parameter and setting its QPalette's background colour to black, however that didn't change anything, I still get fuzzy, greenish text.
I have tried various QBrush and QPen colours in the QPainter.
I'm really close using a QPainterPath in an overidden paintEvent function (in a class extending QLabel) where I paint a black path of the text behind the text, then I call QLabel::paintEvent and let it draw the text over the top. The issue here is that in some cases the path is clipped to smaller than the widgets rect() on the left hand side, scope for another question I think!
What I could try but haven't worked out yet
I could give the text a black outline as per this question however I'm using a QWidget not a QGraphicsView text item, and then the black outline would still probably blend with the green background.
Compromises I've already thought of and want to avoid
I could set the QLabel background to black, leaving large rectangles of black over the resulting overlay, unfortunately the labels are often much larger than the text being displayed.
I could stop the font being anti-aliased, this looks quite ugly and it stops all fonts being uniform across the product.

Resources