Any way to restrict the full resolution image from being served up with Imageprocessor in Umbraco? - umbraco

I'm working on a photography website in which full resolution photos can be uploaded but full-res should not be able to be displayed/accessed (download of the full res will take place through a token.)
I've tried the "restrictTo" setting but resolutions need to not be reliant on specified dimensions.
Is there a way to have myphoto.jpg by default without a querystring display at for example 700x700 yet still have the full resolution file available through a token download? Pretty much, an image without a querystring is still processed by Imageprocessor but with a default resize rule.

I can request an image with a native width of 5000px by myphoto.jpg?width=1400 but the resulting image is the full 5000px width image, why doesn't the max width 1400px image serve up?
If you are getting the full image back it means something has gone wrong. (You've probably ran out of contiguous memory) so make sure you're in 64bit mode.
maxWidth restricts the resize param to an upper limit only. So does nothing on it's own.
What you are probably looking for is the ValidatingRequest event
http://imageprocessor.org/imageprocessor-web/imageprocessingmodule/#events
I would first set ImageProcessor.Web to intercept all image requests in the processing.config file by changing the interceptAllRequests property. That will ensure you capture any attempts to view the image without a token.
In the event you can cancel the request and also alter/add any querystring parameters to limit your size transparently without showing the querystring to the end user.

I would use a query string for the image.
url?width=1400&height=900&mode=crop&anchor=center
I would also use a lazy load so the page loads faster with small blurry images and then afterwards replaces them all with the full res or querystring for max size you want to display at.
I wrote a script for this.
http://www.codeshare.co.uk/blog/lazy-loading-images/
Also on my site now, when I upload an image, I automatically resize it down to 1080p resolution when it saves. So I can upload a massive image and not have to worry about resizing it first or it taking up too much space on my server.
Here's the code for that too
http://www.codeshare.co.uk/blog/automatically-resize-your-media-images-in-umbraco/

Related

Rails image manipulation

in our website we are retrieving data from an API, which does not pull images bigger than 100 × 75 pixels, then we show them listed. example We need to double up this size to match with our design.
Is there any Gem that does this, without loosing quality and not impacting performance?
There is no way to upscale an image without losing quality - you're basically asking an algorithm to fill in image data that simply does not exist in the file in the first place.
However, depending on the rate of the scaling and the images themselves, you could have acceptable results.
Since you want to do this effectively and there is no benefit of doing the resizing on the server anyway, I'd advise simply using CSS to achieve this on the client side - just set the desired width/height attributes for the specific img elements.
If you really want to do this on the server (e.g. if you need to save the resulting images), one option would be to use the Paperclip gem's image processing capabilities.

Download #2x and #3x images from server to Tableview

I have a tableview that is populated from images on my server that I download. My question is How would I go about getting different images for the different resolutions for the devices? 6 vs 6plus etc?
Do I write code that is device specific? e.g
if device is equal to 6 load #2x images 'from #2x url'
else if
device is equal to 6 plus load #3x images 'from #3x url'
and so on.
Or is there a more efficient way of going about this?
You've got several options, depending on the back-end technology stack you're connecting to.
Options if you're using a custom server that you've built yourself, or have control over the code:
Add device scale detection into your image service that checks the inbound user-agent for device scale, and serves the appropriate image for that device. This is hands down probably the simplest solution to implement if you manage your own back-end.
Write into your API a url path param that serves the appropriate image scale; you can then use the UIScreen class (UIScreen.mainScreen().scale) to adjust your target URL accordingly, e.g.:
https://api.yourbackend.service/images/{imageid}/#2x.jpg
This is arguably more difficult to implement, but it's also a lot more robust (doesn't rely on potentially changing user-agent strings), and it's a lot cleaner when logging or querying analytics.
You could probably also use something like retina.js to handle this on your back-end, though I can't tell you whether or not it will work heedlessly (haven't tried it).
Options if you're using a CDN image host:
Use their built in HiDPI support (Cloudinary, for example, provides this -- read about it here).
If your CDN doesn't support this, switch to one that does ;)
You are coming at this exactly backwards.
A table view cell's image view is tiny. You are not going to be showing these images at full size anyway. So there is no point whatever downloading larger and larger images only to be displayed at tiny sizes. That's a massive waste of time, bandwidth, and ultimately memory (if you really try to display large images in every cell, you will run out of memory and crash).
If you have a choice of image size to be retrieved from the server, you should be doing just the opposite of what you are suggesting: download a thumbnail of your image suitable for display in the table view. If the thumbnail is twice the size of the image view, it will look good at all resolutions with minimal waste of memory.
If this app is about also fetching the real full-sized image, outside your table view, you can do that later when requested by the user.

When to use double size images

I was thinking to write some quiz app where questions are represented as images.
My question is, for each quiz question (question.jpg), and thus a jpg file, do I have to create
a double sized question#2x.jpg file?
Is it necessary?
Doing this seems will increase size of my program so I was thinking when/if this is necessary to do?
PS. And in case I have to do it, I will just have to double in size each image manually and add to the project right (both original and double sized image)?
PPS. Just to add more info. The questions are located on the web site, I have to download them and add to my project manually (like resources). On web site there are no different versions of the same image. So, I have whatever is on the web site. Some images I noticed are 800x600 in dimensions but some are also in dimentions 500x400. So after I download these images, how shall I name them? Just with original names? and forget about the #2x extension? What's the best practice?
(if this will help my image view will probably be smth .like 310 in width). Do I have to modify them in size? What to do?
Apple's naming conventions of high resolution images can be found here:
Apple doc naming conventions
If you are developing in the way that you want to support old screen as well as retina screens. You can use xxxx.jpg for old devices as iPhone 3gs and iPad 1, and use xxxx#2x.jpg for retina displays. Where the aspect ratio needs to be the same but the #2x image needs to be twice as big.
In your case "my image view will probably be smth .like 310 in width", then the #2x image needs to be 620px in width and normal revolution 310px.
There is actually no need to have both image sizes in the app as you can use the same image and just scale it(If you really really need to have the old resolution supported).
Even if you add just a #2x, it will scale itself if someone on an old device installs your app. It may become a bit blurry but will still be quite ok.
If you are planning to use a lot of images in your app I suggest using some sort of web service where the user can download content that is to be shown. But that's just me. As the app will quite quickly become very large as images takes up quite a bit of space. Of course this all comes down to how many images you will have.
The drawback of using a web service is that the user much have an internet connection to be able to play. And download your content.(Most quiz apps I know of does use a web service for this.) This is a matter of taste.
If you do need to support normal and #2x here us a method you can use. This method will return the scaled image so you just need the normal one or the #2x one and then scale to the other size. This will at least help you a bit when it comes to getting either your app size down or your clients download time down.
If you are using .jpg's and scaling them upwards you can quite easily get a pixalated image as it is a lossy format. But if that's what you still want to do and maintain aspect ratio, this is one way to do it:
-(UIImage*)resizeImage: (UIImage *)imageToScale withScale:(CGFloat)theScale{
UIImage *image = [UIImage imageWithCGImage:[imageToScale CGImage]
scale:(imageToScale.scale * theScale)
orientation:(imageToScale.imageOrientation)];
return image;
}
Usage
[self resizeImage:[UIImage imageNamed:#"question.jpg"] withScale:0.5];
0.5 would double the size and 2.0 results in an image half the size as the original.
If you want a more complex method to set for instance set a specific target size just say so and I'll edit this answer.

Webmatrix - webimage crop then resize

I want to make sure that all the images that users upload to my website are the same size.
The size that I want to achieve is 620px x 405px
Because I don't want any white space in my images, and I want to keep the aspect ratio, I'm guessing I'll need to crop first, before I resize?
So far I've got the following code:
photo.Resize(width: 620, height:405, preserveAspectRatio: false, preventEnlarge: true);
But obviously this isn't giving me the desired affect.
I have seen other articles online where they do some formula, but I can't get any to work for me.
Suppose someone uploads an image which is 1020 wide by 405? Which bit do you want to keep? The left hand end? Right hand end? The middle bit? Then the next image is 3000 x 3000. Now which bit do you want to crop? Perhaps this one needs resizing before cropping otherwise you might only get a window.
My recommendation is to allow the user to specify the crop area, and then you resize the resulting cropped image. There are a number of jQuery plugins that enable client side cropping. I've written about jCrop (http://www.mikesdotnetting.com/Article/161/WebMatrix-Testing-the-WebImage-Helper-With-JCrop) but I have also received some feedback that it is not reliable in some versions of IE (although I haven't tested that myself).

What might cause a partially loaded JPEG in a UIImageView?

We are getting reports in the field, on both iOS and Android, of partially loaded profile images in our mobile app.
Here is what it looks like (note that I have gaussian blurred part of the image to protect the privacy of our members, but the grey is what is actually rendered):
AFAIK there is not a concept of loading "Progressive JPEGS" in UIImageView, so I am at a loss about how this image could even have been rendered at all. This code has not been modified in at least a year. All images are hosted on S3, and have been for 2 years.
Is it somehow possible that carriers are truncating images now if a device hits a certain bandwidth limit?
-- Edit --
I can confirm we were able to repro this behavior on an AT&T network. Is it possible that AT&T is munging images in this fashion when a user goes over his data cap or something?
I had this same issue crop up when I switched from https to http images. Needless to say... I switched back to https based images.

Resources