Resizing an image with mini_magick - ruby-on-rails

My service has both a web version and an iPhone version. On the iPhone, we ensure that users submit a square version by having it crop when it uploads. We are allowing uploads on the website as well, but we do not have such a feature.
As such, I would like to scale any uploaded image into fitting a 612 * 612 area. What would be the best way to accomplish this?
I am using Ruby / mini_magick

You'd just use the resize method from MiniMagick, there's an example on the Github page:
https://github.com/minimagick/minimagick
Presumably you have the image as a bunch of bytes in memory so something like this:
image = MiniMagick::Image.read(your_image_bytes)
image.resize('612x612')
scaled_image_bytes = image.to_blob
# Or image.write(filename)
MiniMagick uses standard ImageMagick geometry strings for sizing and, from the fine manual, a WxH geometry:
Maximum values of height and width given, aspect ratio preserved.
so using '612x612' will scale the image to fit within a 612px square while preserving the aspect ratio.
You could also use Jcrop to allow your web users to crop the their uploaded images to fit into a square.

Related

IIIF image processing like iiifhosting.com

I want to know that is there any existing feature that cantaloupe offer to resize low resolution images to high resolution like iiifhosting.com is doing?
For example, if I have image of 1000x750 and upload it to directory. When i access with cantaloupe end point url like,
{scheme}://{server}{/prefix}/{identifier}/info.json
https://example.org/image-service/abcd1234/info.json
I got width = 1000 and height = 750 of image in json response.
I want to increase that width and height of image to something like 6117x4112.
I am asking this because i am using mirador viewer in my web application and mirador viewer does not zoom in and zoom out low resolution images.
Before that i was using iiifhosting.com now i want to setup my own server.
When i upload images on iiifhosting.com like i have uploaded 1000x750 image on iiifhosting.com and when i access image info.json
{scheme}://{server}{/prefix}/{identifier}/info.json
it gives me width and height of image to higher scale like some greater values 6117x4112. Please let me know how i can achieve that.
Thanks.

Force user to crop/upload an image to a certain size? Preferably using filepicker

I have users uploading images using filepicker, but I want them to have to upload an image of a certain size (and crop if the image is too big). I could cut it myself, but then it won't look good. Ideally, the user would crop it themselves.
I've tried this page: https://www.filepicker.com/documentation/file-ingestion/widgets/pick?v=v2 and I've tried various options but nothing seems to work quite well.
data-fp-image-min doesn't prevent users from uploading smaller images. data-fp-crop-force along with data-fp-crop-max and data-fp-crop-min doesn't do the trick either.
I'm open to using other image uploading libraries, but I like using filepicker. Seems like this is something other people would have run into.
I'm using rails btw.
From the docs:
data-fp-image-min - Images smaller than the specified dimensions will be upscaled to the minimum size.
So it doesn't really prevent users from uploading smaller images.
data-fp-crop-max and data-fp-crop-min specifies the maximum and minimum dimensions of the crop area so it won't give you specific dimensions.
I would recommend you to:
Set data-fp-crop-ratio - Specify the crop area height to width ratio. User will be able to adjust the crop area for each photo with desired ratio.
Set data-fp-crop-force="true" - User could not skip cropping image.
Then resize image to specific height or width.
This will result, you will always get the image with the desired dimensions.
Example for 150 x 200 image output:
Html widget:
<input type="filepicker"
data-fp-crop-ratio="3/4"
data-fp-crop-force="true"
mimetype="image/*"
onchange="window.upload(event)"
data-fp-apikey="APUGwDkkSvqNr9Y3KD4tAz" />
Javascript:
window.upload = function(event){
console.log(JSON.stringify(event.fpfile));
var listElem = document.createElement("li");
var image = document.createElement("img");
/*
set w=150 (width) conversion option
so all images would be 150x200
and crop_first option to make sure the image is cropped
before any other conversion parameters are executed.
*/
image.setAttribute('src', event.fpfile.url + '&w=150&crop_first=true');
listElem.appendChild(image);
document.getElementById('results').appendChild(listElem);
};
Here is working solution: http://jsfiddle.net/krystiangw/9o9ebddL/

How to get rid of empty transparent areas in a PNG image so that it conforms to actual image size?

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.

Blurry Images when rendering to PDF using UIKit/Coregraphics

Everything seems pretty standard I downloaded PDF GENERATION SAMPLE and used my own assets at normal resolutions and my images look a little off.
Here's the asset
Here's what it looks like in app
And this is what it looks like in the PDF at 100% zoom
The code in the drawImage function is as simple as it gets
UIImage * demoImage = [UIImage imageNamed:#"icon_map_project.png"];
[demoImage drawInRect:CGRectMake( (pageSize.width - demoImage.size.width)/2,
350,
demoImage.size.width,
demoImage.size.height)];
Nothing fancy at all. I do admit that my familiarity with the details of how PDF work, DPI, and things like that are beyond me at this point.
I've looked at LibHaru and think it's a great system but I'd rather keep this within the confines of UIKit/CoreGraphics.
You'll notice a strange jaggedness on the right side, even shrinking the image down by 50% doesn't seem to help.
Here's a zoomed up image using Digital Color Meter with the PDF at 100% and then the app
As you can see the image simply does not render correctly into the PDF and I'm struggling to find a solution for this.
Thanks for any advice.
You draw the image in the PDF in a rectangle that matches the image size. This results in a 72dpi for the image. Because the viewer application use 96dpi or a higher value as reference for 100% zoom, when the file is displayed at 100% your image will be rendered 100% * 96/72 scale. If you enlarge the bitmap at that scale with an imaging tool you'll see a similar jaggedness. The solution is to use a larger image drawn in a 37x36pt rectangle so that the resulting image dpi is higher.
If you zoom your PDF file to 75% the image size displayed on the page should match the image size in your application (this assumption is based on a 96 dpi screen).

How can I scale an image with ColdFusion without losing resolution?

Server Config:
Windows Server 2003
IIS 6
ColdFusion 8 Standard Edition
Java Version 6 Update 18
I have a ColdFusion application that allows users to upload images that will be added to an existing PDF. When the images are added to the PDF, they have to fit within a minimum/maximum height and width, so the uploaded image needs to be scaled to fit.
For instance, let's say the minimum height and width for a given image is 100x100, and the maximum height and width is 200x200, and the user uploads an image that is 500x1000. I use the logic below to scale that image down without skewing the image (it keeps its original shape) to 100x200. For an image smaller than the minimum, it is scaled up (in the example above, a 50x50 image would be scaled up to 100x100).
The problem I'm noticing is that when ColdFusion scales the image using its built-in functions, it reduces the resolution to 72dpi. Is there a way to prevent this loss of resolution, as the images are being added to PDFs which need to be print-quality?
Here's the [scaled-down] code I'm using to scale the images:
<cfscript>
imagePath = "/uploads/image.tif";
scaledWidth = 100;
scaledHeight = 100;
scaledImage = ImageNew(imagePath);
ImageSetAntialiasing(scaledImage, "on");
ImageScaleToFit(scaledImage, scaledWidth, scaledHeight);
</cfscript>
I think you may want to skip scaling the image at all and add the original image to the pdf document. Then have whatever pdf creation tool you are using "resize" and position the image on the document canvas. Similar to setting width and height on images in html to something other than its native resolution. I have not had to add images to PDFs docs like you described but this post might point you in the right direction:
Adding a dynamic image to a PDF using ColdFusion and iText

Resources