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

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

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/

Responsive image size both image (pixel) size and file (byte) size just like in Google plus

The link below is an example image link I got from google plus. If you change the width value of the URL, the image size change as well and it has a smaller file size. For example, change the width from 1017 to 100
http://lh6.googleusercontent.com/-Eanf6uMoTPI/VaP0qYA_jUI/AAAAAAAAJcc/dOua5XQcjPE/w1017-h678-no/IMG_9439.jpg
File size: 216.8kB
http://lh6.googleusercontent.com/-Eanf6uMoTPI/VaP0qYA_jUI/AAAAAAAAJcc/dOua5XQcjPE/w100-h678-no/IMG_9439.jpg
File size: 12.5 kB
Can someone please give an advice on how can I have this feature in my web application, regardless if it uses file system or database. This feature is ideal for displaying thumbnails or resizing images.
Thanks in advance
My solution to this (by the way) was to use SLIR application by Lencioni. It can crop or resize without altering the original image. It uses a cache to store the resized images to lessen the server load.
https://github.com/lencioni/SLIR

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.

Resizing an image with mini_magick

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.

Resources