Elixir Imagemagick gravity offset - imagemagick

I'm sticking two images together, putting them in a frame (the template_image is the frame) with some text (a title and artists name). Doing it in Elixir.
Combining the images so that they are stacked one above the other works (append).
Compositing the image and the frame image also works.
My problem is with positioning the text on the newly composited image. I use
"-gravity",
"SouthWest", # this doesn't position bottom left
to position the placement of the text. However, it attaches itself to the bottom of the first image that was appended... not to the bottom of the newly composited image. It's as if it does not see the size of the new image.
How can I correctly set the position so the text appears where bottom left. Thanks.
[
"#{original_file_path}[0]",
"-resize",
"500x500",
"#{original_file_path2}[0]",
"-resize",
"500x500",
"-append",
"-background",
"Black",
"-gravity",
"center",
"-extent",
size,
template_image.path,
"-gravity",
"center",
"-composite", # new image created
"-gravity",
"SouthWest", # this doesn't position bottom left
"-fill",
"white",
"-font",
"arial",
"-pointsize",
"22",
"-annotate",
"+10+40",
title,
"-fill",
"white",
"-font",
"arial",
"-pointsize",
"12",
"-annotate",
"+10+20",
artist_name,
"-quality",
"85",
destination_path
]
end

Added +repage immediately after -composite as per Mark Setchell's comment. It worked. I can't take the credit for this one - thank you Mark Setchell.
The Docs say:
Use +repage to completely remove/reset the virtual canvas meta-data
from the images.
So Repage appears to reset the meta-data pertaining to image size and positioning etc - so imagemagick has the correct information to perform the next operation etc.

Related

How do I cover a 2D array of colors with the fewest possible colored rectangles?

I'm creating a game that takes an image represented by a 16x16 array of html color codes and creates a 3D object made out of rectangular cuboids. Like taking the Paint program on Windows and extruding your image into the Z axis.
// An image containing 16 columns and 16 rows of hexcodes for 256 total hexcodes
[ [ "#FF5733", "#FF5733", "#FF5733", "#FF5733", ... ], [ "#FF5733", ... ] ]
How can I create the smallest possible array of rectangles that would cover the image without creating overlapping rectangles?
// Rectangles that represent the 2D image, a blank image would have only one rectangle
rectangles = [{
color = "#FF5733",
x = 5,
y = 3,
width = 5,
height = 5,
}, ... ]
My first attempt at a solution --- every single pixel in the 16x16 image getting a cube (256 cubes) --- created huge load times (30 seconds) for loading 500x 3D images.
One improvement I was able to make was "reading on" past the current color in the row until I hit a different color or the end of the row in order to create long rectangular cuboids across the row. This improvement cut the cuboid count in half. Extending this trick across the y axis has proven difficult. Overlapping rectangles look really ugly.
My understanding is that this problem is NP Hard. I'd be happy if we had a solution that had fewer rectangles even if its not provably the fewest rectangles.
The Wiki Article on the problem does not give any concrete suggestions.

Make an image in Kivy exactly the same size as the widget bounding box

I'm having trouble in Kivy setting an image size. I want to keep the aspect ratio fixed but I also want to position things precisely over the top of the image.
To do this, I make a RelativeLayout that has the same size and position as the image. However, when I check the size of the layout, it is always slightly larger than the displayed image. Making precise alignment very difficult. The wiki mentions something like this:
By default, the image is centered and fits inside the widget bounding box. If you don’t want that, you can set allow_stretch to True and keep_ratio to False.
They also include code if you want to make the image slightly larger than the containing widget:
<-FullImage>:
canvas:
Color:
rgb: (1, 1, 1)
Rectangle:
texture: self.texture
size: self.width + 20, self.height + 20
pos: self.x - 10, self.y - 10
But nothing about making them exactly the same size!? Surely I should be able to dictate the containing widgets size so the aspect ratio etc. is exactly as required.
I have tried many things but whatever I try, I cannot get the outside edges of the displayed image and a layout to coincide.
Does anyone have any experience with this?
Apologies, I have discovered the problem, the images had a transparent border that I wasn't aware of (the images were passed on to me from elsewhere) I have removed this and it has solved the problem.

Apply PanoTools alignment to individual images

I have batch of images (timelapse fotos) which I aligned using
align_image_stack from PanoTools, because the have some small shifts. The required positional shift relative to the first image is specified as roll/pitch/yaw values in the output PTO file. How is it possible to apply excatly these positional shifts to the images? I mean if it gets shifted to the right for example, then it gets some (black) border at the left and cropped off at the right.
Then I could afterwards crop out the area inside the border to get an unshifted timelapse.
I just realized the -a option of align_image_stack does this!

How to remove white space between ImageMagick's montage tiles?

I current have code that build a montage using ImageMagick. This is my line of code:
montage -mode Concatenate -tile ${tile} -geometry ${geometry}+0+0 ${input} ${output}
I'm using -label ${label} to name my labels (in my input var).
This gets me a montage with a lot of white space, like that:
I checked on the manual and forums but everyone seem to agree that the way to do this is to use concatenate or geometry +0+0. I am already using those and it does not work. I also read that the font should be automatically chosen to fit the free space. Right now, there is way too much white space.
My goal: To get the white space (between the tiles on the vertical) to fit the current labels height and nothing more.
If you have an idea, I would be really happy.
Thank you anyway guys!
PS: It also doesn't work without labels. I get:
PPS: I'm sorry if my english is not really good, I am french from Montréal, Qc, Canada.
UPDATE: Those are my settings:
tile=4x3
geometry=386x305
The additional white space is coming from your geometry setting. The options -geometry 386x305+0+0 is adding an additional 15px between the image and the label.
If you omit the WxH and add a non-zero value to the offset -geometry +0+15, then you'll have additional white space after the label.
To limit the white space to text height, and nothing more, just keep the option as -geometry +0+0.
I also read that the font should be automatically chosen to fit the free space.
I think that's reversed. The white space is determined by the typeface of the font. I wouldn't say fonts automatically adjust <blank>, but default to <blank>. It's always a good idea to define the font & pointsize.

objective-c, psd, makeup

Does anybody know how to make correct image and (UIlabel)label position for iphone and ipad
according to the layout image in psd file.
I'm using photoshop. I take a ruler look for the highest letter in the sentence(which should be positioned) and move it to the top of psd image, than take the left extreme letter and move ruler to the left.
Then i make a screenshot of the ipad/iphone screen and compare the x,y of psd and png file.
if psd x/y more then png x/y i make the next steps: Xpsd - Xpng, Ypsd - Ypsd, and if the coordinates of psd less than png i make Xpsd + Xpng, Ypsd + Ypsd.
And finally i have wrong visual position in ipad/iphone!
The most common reasons why the visual position/dimensions of a given element don't match what you think they should is typically the auto resizing mask that is applied to the particular view in question.
For example, your UILabel should have its autoresizing mask set to:
label.autoResizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin;
This will keep your label aligned to the top left, and will not allow its height, nor its width to be changed depending on the super view's size changes.
This can also be set in interface builder with these controls:
The outer lines match the margin sizing, if it is a solid red line, then that means that as the superview's size changes, the current view's position relative to those edges will be preserved.
The Inner lines represent a flexible width, and height. If it is a solid line, then that means that the current view will resize to retain the same proportion of the superview's size.

Resources