How to center align watermark when using burning image plugin in Grails - grails

I need to apply watermarks to the uploaded images. According to the documentation for the burning image this is done with following code:
def orginalFileName
burningImageService.doWith('path/to/my/file.jpg', 'path/to/output/dir')
.execute {
it.scaleApproximate(800, 600)
orginalFileName = it.watermark('path/to/watermark',
['right':10, 'bottom': 10])
}
.execute ('thumbnail', {
it.scaleAccurate(200, 200)
})
Is there an easy way to center align the watermark without needing to calculate the coordinates? I cannot use the given size (800,600) since it is an approximate size. I cannot use scaleAccurate because I don't want to crop the image.

Just remove the position coordinate from the parameters and it will center the watermark by default.
burningImageService.doWith('path/to/my/file', 'path/to/output/dir')
.execute {
it.watermark('path/to/watermark')
}
For more info please refer:
https://code.google.com/p/burningimage/wiki/Images_manipulation_handling

Related

google docs api - insert inline image not resizing image to specified size

so I have been making some image requests with the google docs api using javascript, but I have been unable to change the image size when I make the request.
All the images seem to be appearing in their original size in the google doc.
So I am wondering what I am doing wrong. The documentation seems to be pretty clear:
https://developers.google.com/docs/api/reference/rest/v1/documents/request#InsertInlineImageRequest
Basically it just says to specify objectSize width and height, using magnitude and units (PT).
Here is the function I use to append to my full request, where I specify all of these.
function imageRequest (url: string, width: number, height: number) {
const request:Array<object> = [ {
insertInlineImage: {
uri: url.toString(),
objectSize: {
height: {
magnitude: height,
unit: 'PT'
},
width: {
magnitude: width,
unit: 'PT'
}
},
location: {
index: 1
}
},
} ];
return request;
}
And then I'm pushing each image request to the full request like.
request.push(imageRequest(image.image.url, 468, 648));
but whatever I put for the width and height is not doing anything. The images are always the original size.
The images are public on an s3 style hosting at Wasabi (similar to amazon s3)
I cannot think of what the problem could be, maybe it's something small that I am overlooking?
help is appreciated, thanks.
The image dimensions are defined by the objectSize property and the Docs documentation states a few rules that define the final size of the image:
If neither width nor height is specified, then a default size of the image is calculated based on its resolution.
If one dimension is specified then the other dimension is calculated to preserve the aspect ratio of the image.
If both width and height are specified, the image is scaled to fit within the provided dimensions while maintaining its aspect ratio.
From these rules it seems that Docs will prioritize the aspect ratio of an image over the exact size, so even if you specify a certain set of dimensions, Docs may resize it to preserve the ratio. As a workaround you can specify only the dimension that you deem more important, (width or height) and Docs will calculate the other one automatically.
In addition, it seems that Docs uses points (PT) rather than pixels (PX) as units to measure dimensions. One point is 1/72 inch while one pixel is 1/96 inch, so if you're used to calculating sizes in pixels as it's most common you'll need to make this conversion as well. A pixel will be 0.75pt while a point will be 1.333...px.

Reset Line position after window resize

I'm developing an App where I want to draw lines on an Image. The Image can be zoomed in and out, and dragged. I used self.to_widget() method of the Scatter class, so that the coordinates with respect to the Image will remain the same after zooming and dragging.
I wanted to implement a reset button, that would allow to reset the position and size of the image with respect to the the Window size. Here I'm facing the problem that the coordinates of the lines are changing with respect to the Image.
Knowing that the Image is a Child of a Scatter class with id: scatter_class, here is the code for the reset button:
def reset_position(self):
self.initial_width = Window.size[0]
self.initial_height = Window.size[1]
self.ids.scatter_class.pos = (
self.initial_width * 0.25,
self.initial_height * 0.5 - self.ids.main_image.height * 0.5,
)
I read that making changes in a Scatter class, won't affect its children, that's why probably the Line position are not updating with respect to the Image. I tried updating the position of the Lines using the to_widget() Method, to recalculate the coordinates with respect to the new position and size of the image, but it seems like I'm missing something.
Any Ideas?
Thanks in Advance!

Magnifying Lens examples using JUNG

I am trying to use the JUNG library on a project.
But I am having trouble identifying if there is a simple way already to change the size of the magnifying lens on the example projects.
Currently in all the examples the magnifying lens are bounded to the size of the graph view and to the window size.
Is there a method to set only the size of the lens and break the link to the window size?
I am using the latest available JUNG version.
Thank you so much in advance!
regards,
Nelson
The local fix that you made (adding a constructor parameter to ViewLensSupport to specify the lens size directly) appears to be both necessary and sufficient to fix your problem.
I agree that it makes sense to be able to control the lens size independently; feel free to send us a pull request: https://github.com/jrtom/jung/pulls
Did you see that you can use the mouse to resize the lens by pressing and dragging on its edge? The code that is called in that case is this:
lensTransformer.setViewRadius(r);
In the edu.uci.ics.jung.samples.LensDemo, I was able to set the initial size of the lens (to 20) by modifying the code like this:
(Note that you can still use the mouse on the edge of the lens to resize it later)
final JRadioButton hyperView = new JRadioButton("Hyperbolic View");
hyperView.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent e) {
hyperbolicViewSupport.activate(e.getStateChange() == ItemEvent.SELECTED);
// added to set the lens size to 20
if (e.getStateChange() == ItemEvent.SELECTED) {
MutableTransformer mt = vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW);
((LensTransformer) mt).setViewRadius(20);
}
}
});
final JRadioButton hyperModel = new JRadioButton("Hyperbolic Layout");
hyperModel.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent e) {
hyperbolicLayoutSupport.activate(e.getStateChange() == ItemEvent.SELECTED);
// added to set the lens size to 20
if (e.getStateChange() == ItemEvent.SELECTED) {
MutableTransformer mt = vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT);
((LensTransformer) mt).setViewRadius(20);
}
}
});

RMagick - how to create a thumbnail with an automatic height?

I am using RMagick for creating thumbnails like this:
img = Magick::Image.read(image_url).first
target = Magick::Image.new(110, 110) do
self.background_color = 'white'
end
img.resize_to_fit!(110, 110)
target.composite(img, Magick::CenterGravity, Magick::CopyCompositeOp).write(thumb_path)
This works well - I'll load the current image, create a "space" for the new thumb and then will place it there.
However, I would need to create a thumb where would be the width 110px and the height would be automatically counted... How to do this?
Thank you
You'd rather use resize_to_fill!
Doc here
image = Magick::Image.read(image_url).first
image.format = "JPG"
image.change_geometry!("110X110") { |cols, rows| image.thumbnail! cols, rows }
image.write("<path to save thumbnail>")
This turns out to be super easy! ImageMagick and GraphicsMagick both maintain aspect ratios properly, so in your case, just give the max width you want the image to be. See http://www.imagemagick.org/script/command-line-processing.php#geometry to learn more about the magick dimension operators.
If you find that you're ruby process' RAM consumption is growing, you may want to switch to an external-exec image library, like https://github.com/mceachen/micro_magick. Also, switching to GraphicsMagick is an all-around win, BTW, giving better image encoding and in less time.
require 'micro_magick'
img = MicroMagick::Convert.new("input.png")
img.resize("110") # this restricts to width, if you want to restrict to height, use "x345"
img.unsharp(1.5) # This runs an "unsharp mask" convolution filter, and is optional
img.write("output.png")

How do you get Highcharts to scale up image contents rather than add more details?

I am trying to generate PDF documents server side containing data tables and charts generated by HighCharts. I am using highchart-serverside-export and iText.
I have been able to generate the documents but the chart images are grainy when printed. From what I understand, iText uses 72dpi by default when inserting an image. The correct way to get higher fidelity images is to start with a larger image and scale it down using one of the scaling functions such as scalePercent().
I can easily generate a larger chart image by passing in larger height and width parameters to Highcharts. The problem is that when you increase the dimensions of the chart, the content does not scale up (eg. font size of lables). In fact, you get more detail in some places (eg. more axis ticks). The reason this is a problem is that when you then apply the scaling down via iText, these items become very small and hard to read.
I have looked at the Highcharts API and cannot see a way to get Highcharts to scale up the contents rather than add more detail. How do I get this to work?
If the approach I am using is completely wrong, the wider question is how do I get print resolution server-side Highcharts charts? I have to use iText but am willing to try an alternative technology to do the chart rendering.
try this
exporting: {
sourceWidth: 1000,
sourceHeight: 400,
},
Link to JsFiddle
You can specify the width of the exported image using the exporting.width property.
This will not increase the size of the div or add/remove details or anything of that sort, it will simply scale the generated svg according to the specified width, maintaining the aspect ratio. Hence also scaling everything including texts etc.
exporting: {
width:2000 // or scale down to 100
}
Upscaling exported images / pdf | Highcharts & Highstock # jsFiddle

Resources