With Graphicsmagick, how to combine 2 images and text in a certain format? - graphicsmagick

I need to combine 2 images and a short text into one image, in the format that the first image is at the top spanning a row, and the other image at bottom left, the text at bottom right.
The produced image is 400px * 600px, the input images can be any size, if the first image is less than 400px, it will be centered at the top
Is it possible with Graphicsmagick?

Assuming you already have two images called:
top.png (image at the top spanning a row)
left.png (other image at bottom left)
first of all you have to create the third missing image (called text.png) containing your text:
gm convert -size 200x300 xc:#7F0000 -pointsize 80 -font Arial -fill white -draw "text 10,150 'text'" text.png
then you can compose the two images in the bottom part (creating an image called bottom.png):
gm montage left.png -geometry 200x300+0+0 text.png -tile 2x1 bottom.png
and finally you can compose upper and lower parts with:
gm montage top.png -geometry 400x300+0+0 bottom.png -tile 1x2 result.png
the result will be an image called result.png, size: 400x600
top.png:
left.png:
result.png:
Tested on Windows with GraphicsMagick 1.3.18 2013-03-10 Q8

Related

How do I draw with inverted color in 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.

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

Crop image in R

I am trying to crop an image using the magick package in R. My goal is to crop the upper left corner portion of the image. So far my code seems to work for some images but the same dimensions do not work for other images.This is my code:
library(magick)
library(tidyverse)
image_read("http://www.gettyimages.com/gi-resources/images/Plugins/Chrometab.jpg")%>%
image_chop("0x185+190")%>%image_crop("50x55+1")
I am doing this for several images all of which have the dimensions width 320 height 240. This code seems to work for some of the images but crops portions other than the top left corner for some of the images. Is there a way to modify my code such that irrespective of the picture dimensions, it will always crop the top left corner.
I do not know R, but if I use the equivalent imagemagick commands, your chop is cropping approximately, the bottom half of the image and the subsequent crop is cropping the top left corner of the chopped bottom part. Why are you using chop? Also after a crop, the image will have a virtual canvas left if you save to PNG or TIFF that should be removed by using +repage. Not sure what that is in R, but may be repage +0+0. If you want to crop the top left corner, just use -gravity northwest and crop with the size you want WxH+0+0, unless you want an offset in place of +0+0
convert Chrometab.jpg -chop 0x185+190 +write tmp1.png -crop 50x55+1 tmp2.png
tmp1.png
tmp2.png
Whereas:
convert Chrometab.jpg -gravity northwest -crop 50x55+1+0 +repage tmp3.png
tmp3.png

How to remove the white margin of ggord in ggplot2?

I have this plot. I am using the following package and script to do a biplot. But the figure output always has white margins on the top and bottom of the actual figure. I tried removing them using plot.margin=unit(c(0,0,0, 0), but no luck. Any thoughts on how to do this or is it just the default and there is nothing that can be done?
The script (I am using the example, but the same issue with mine):
>library(devtools)
>library(ggord)
>ord <- prcomp(iris[, 1:4])
>p <- ggord(ord, iris$Species)
>p
The problem is the white margins on the top and bottom as seen here. How can I remove them?
The white space you are seeing is a function of the window size when you save the image. If you resize your window vertically or horizontally, you'll notice that the white space shrinks or grows.
If your goal is to save the plot as a PNG image, you can export it directly to file with your desired dimensions as follows:
png("plot1.png", 800, 300);
p;
dev.off();
Adjust the 800 to the desired length and the 300 to the desired height, in pixels. If the size is larger than the actual graph, it will pad with blank space.

Scale Image Then Add Whitespace to Create Static Size

I'm looking for a solution to wordpress to an issue i'm having. I would like to have a thumbnail with a static image size, scaled with whitespace added to both sides to fit it to the required image size
So lets say my image is 300px x 99px and I want a 100 x 100 thumbnail.The image should scale down to 100 x 33.
like this: http://wpquestions.com/uploads/durin_phpL9cDfa.png

Resources