I'm currently using Gimp to resize some images. I'm a web developer but I don't really use image manipulation software much as most of the images are provided by designers so the Gimp tool is very unfamiliar to me. I've looked through all of the tutorials and help guides on the Gimp site but I cannot find the answer to the simplest of questions:
How do you resize a layer to fit within the current canvas whilst maintaining the aspect ratio?
I'm essentially setting a fixed size on my Canvas and importing an image as a layer into my project. What I then wish to do is scale this much larger image down so that is can fit within the Canvas with the aspect ratio preserved. I have found a way of scaling the Canvas to fit a layer but this is not what I am looking for.
Any help would be greatly appreciated.
That feature is not in gimp for some reason. An alternative without any scripts is:
Layer -> Scale Layer
This is easy to do, but among the hundreds of possible options to be put on the program UI, it was not "elected" to be there.
The way out is to use the program's scripting capabilities to perform the action:
what have to be determined programatcially is whether the ratio of the image/layer is larger
on the width or height, and use this ratio to scale tha layer, and then center the layer.
For your convenience, I wrote some Python code for this in a single line, in a way you can just copy and paste on the python console (filters->python->console) to apply the effect
on the top layer of the most recent open image.
img = gimp.image_list()[0]; layer = img.layers[0]; factor = min (float(img.width) / layer.width, float(img.height) / layer.height); layer.scale(int(layer.width * factor), int(layer.height * factor)); layer.set_offsets((img.width - layer.width) / 2, (img.height - layer.height) / 2)
Since this can be done, but is not practical, even more because it does not allow you to
pick the image or layer to resize, I formated it as a python-script for GIMP as well.
Just check your edit->preferences->folders->plug-ins for your plug-in directory,
paste the contents bellow as a file there (if on Windows, the file must have the ".py" extension. On Linux and Mac OS, any extension would work, but you have to give the file
the "exectuable" property" ).
After restarting GIMP, you will have the new command conveniently located on your Layer menu:
#! /usr/bin/env python
# coding: utf-8
from gimpfu import *
def scale_layer_to_canvas_size(img, layer):
pdb.gimp_image_undo_group_start(img)
factor = min (float(img.width) / layer.width,
float(img.height) / layer.height)
layer.scale(int(layer.width * factor), int(layer.height * factor))
layer.set_offsets((img.width - layer.width) / 2,
(img.height - layer.height) / 2)
pdb.gimp_image_undo_group_end(img)
register("scale-layer-to-canvas-size",
"Scale layer to canvas size",
"Scales the layer to canvas size, keeping the aspect ratio",
"João S. O. Bueno", "Public domain", "2014",
N_("Scale layer to canvas size..."),
"*",
[(PF_IMAGE, "image", "Input image", None),
(PF_DRAWABLE, "layer", "Input drawable", None), ], [],
scale_layer_to_canvas_size, menu="<Image>/Layer/",
)
main()
Note it is the same code than above, but "img" and "layer" are now suplied by GIMP
when picking the action from the menu, and there are two extra calls so that
both scalignand centering are "undone" as a single action -
the remaining code is justtheneeded boiler plate to register
the function with GIMP
After shrinking my canvas using Image -> Canvas (and centering the layers as desired), the Layer -> Layer to Image Size did the trick (without scaling the image). This is with gimp 2.8.16
Layer > Scale Layer worked beautifully for me.
Related
I have a bunch of auto-scanned slides using a slide scanner (Hamamatsu), which I can export from the NDPview software at different magnifications. So far, I have been zooming in to where I get the best resolution of my region on interest and add a scale bar for 1mm (as 1000 um) using the native scale bar option in the NDP view software. I then export the "view" from NDPview to TIFF. This TIFF is then imported into ImageJ (Fiji) where I set the scale using the scale bar I drew. This has been working well, but with over 500 images to do it's a bit of a pain.
Since the TIFF imports to ImageJ with inchxinch dimensions, I figured I can go to Image -> Properties and just change the unit of length to um. To test this, I selected an area to measure. I then compared this to my old method... and the values are completely different. Any idea why? 1 is the old method, 2 is the new method.
I made certain to "remove scale" in the scale bar window between each test. The whole image dimensions are different too:
If the images are all the same magnification and resolution, then as long as you know a measured distance (in pixels) and the physical distance (in microns or mm), you can set it using Analyze > Set Scale...
To do this in a macro you can use
run("Set Scale...", "distance=255 known=1 pixel=1 unit=micron");
where 255 is the distance in pixels for your known unit (1 micron). This can be applied to all TIFFs in a folder if you wrap that line in a loop operating on all TIFFs and save each resulting image.
I'm trying to use a two step process of employing Gimp to delete sections of images and then using Inkscape for the remainder of the image work.
Unfortunately, I'm seeing a resolution change when doing the export to PNG from Gimp.
The exported image is around 50% larger than the original, which impacts the quality.
Is there a way to keep the resolution constant when exporting the file?
Hopefully I'm just forgetting something, since I've spent some time away from image work.
Please let me know if any additional info is required.
In the interim, I'll try another tool to do the Gimp step.
THANKS!
Edit: Updated size to resolution.
For a bitmap/raster image, resolution (for Gimp: "Image print resolution", see Image>Print size) is indicative. The only thing that counts is the size in pixels.
If you have image window set to "Dot for Dot" (Edit>Preferences>Image Windows->General>"Use dot for dot" or View>Dot for dot) the image is displayed with the definition of your screen (around 100PPI fore regular screens, 20OPPI for high def ones (Retina, etc...).
When you create the image (File>New...), you can specify a print definition and a print size, and Gimp will compute the required size in pixels.
Ok.
To describe what I want to do, have you ever used Telerik Crop function Image Editor control?
I want exactly same functionality.
I want to use that control but, I am working on Universal app that has no control like Image Editor from telerik.
That control does are
1. There is a fixed rect or canvas for cropping image.
2. If the original image is in the area of canvas(or Rect) image's opacity = 1(i guess) and if the original image is out of canvas area, image looks dim(maybe opacity 0.5 or some)
3. Constrain original image movement in the canvas.
I will implement this function in Image.ManipulationDelta event.
Do I have to get each point value of canvas? or can I do it by using Width or Height of Canvas?
How Do I do that?
Can anyone help me?
any hint?
I'm not familiar with that particular control, but I think I understand what you want.
To constrain the movement of an Image within a Canvas you can check where the Image will end up in your ManipulationDelta and limit any translation, scaling, and rotation appropriately. If the bounding box of the Image after the transform applies is within the Canvas then apply the transform. Otherwise roll it back and do nothing. I have sample code for this in my blog entry: Constraining manipulations
To dim the area outside of the crop I'd create a shape and fill it with a partially transparent brush. The all-in-one code framework sample How to crop bitmap in a Windows Store app demonstrates this technique. I believe the sample targets Windows Store 8.0 apps, but essentially the same code should work on Windows Store 8.1 or Windows Phone Store 8.1 apps.
I have a series of images that I would look to loop through using iOS's [UIView startAnimating]. My trouble is that, when I exported the images, they all came standard in a 240x160 size, although only 50x50 contains the actual image, the rest being transparent parts that are just taking up space.
When I set the frame of the image automatically using image.size.width and image.size.height, iOS takes into images' original size of 240x160, so I am unable to get a frame that conforms to the actual parts of the image. I was wondering if there is a way using Illustrator or Photoshop, or any other graphics editing software for me to export the images based on their natural dimensions, and not a fixed dimension. Thanks!
I am a fan of vector graphics and thinks everything in the world should be vector ;-) so here is what you do in illustrator: file - document setup - edit artboards. Then click on the image, and the artboard should adjust to the exact size. You can of course have multiple artboards, or simply operate with one artboard and however-many images.
I have read the recent posts on the Highcharts.com website regarding their updated PhantomJS based exporting-server. I have also cloned their github repository and successfully compiled their web-service. However, all files produced by this server are marked as 96dpi, which is inadequate for my purposes. According to somewhat contradictory information on the Highcharts.com website (Here and Here), they are using Batik to rasterize PNG and JPG output, which should make it possible to adjust the DPI settings of the exported raster images. However, the pom.xml doesn't include any batik references and I can't find anything in the source code which indicates that anything other than PhantomJS is being used to produce the raster renditions. The PhantomJS export might be able to adjust the DPI, but I can only find the scale and width options which don't directly adjust the DPI, thus requiring a tedious post-processing rescale (or metadata edit) to adjust the DPI accordingly.
So, the meat of my question: how to adjust the exported DPI of a highcharts chart in PNG and JPG format when using the highcharts java exporting-server?
The release before the last one used both Batik and PhantomJS. The last release uses only PhantomJS. This is why you do not find any Batik references in the pom.xml anymore.
For controlling the dpi of the exported image. You should use the scale parameter. For completeness sake, here is how Highcharts determines the dpi of the exported image.
Controling the size of the exported image
Since Highcharts 3.0 and Highstock 1.3, the size of the exported image is computed based on a few rules:
If the exporting.sourceWidth and exporting.sourceHeight options are set, they take predence. This provides a convenient way of having separate sizes of the on-screen chart and the exported one.
If not, and the chart.width and chart.height options are set, those are used for the exported chart.
If a size hasn't been found yet, and the containing div has an explicit pixel width or height, that width or height is used. Percentage and other non-pixel widths will not take effect. This prevents a common pitfall in Highcharts 2, where charts with the typical 100% width would look out of proportion in export.
If a size still hasn't been found, it defaults to 600 by 400 pixels.
After rendering the chart width the above size, and all text sizes in relation to that, the actual image resolution is determined by exporting.scale which defaults to 2. In practice this means that a 600x400 chart will return an image of 1200x800 pixels by default. The rationale behind this is quite simple - if we used a scale of 1 and just set the sourceWidth to 1200 and sourceHeight to 800, all the text would become too small. And if we didn't scale it up, the resolution would be too small for print.
Read also here for more on the export server