crop image without disturbing aspect ratio - image-processing

** In image processing, while cropping images, aspect ratio is maintained on any site or app.
Even uploading images as profile photo on whatsApp and Facebook, we cant edit both height and width separately
Why we cant edit the way we want **

Almost all image editing programs have an option to control whether aspect ratio is constrained or not while cropping. Sometimes one wants to guarantee the same aspect ratio and sometimes one wants to crop to a different one for a specific purpose. In fine art printing, crops are usually unconstrained to either match a specific paper size or to make sure the edges hit exactly where the photographer wants them to. (Resizing without preserving aspect ratio is almost never useful on photographs.)
For creating a profile photo, the desired aspect ratio constraint would be the one the site prefers or imposes, not the original one for the image. This immediately creates user confusion if the target ratio is not the one of the uploaded photo because most users do not understand the constraint and would wonder why they can't just use their entire photo.
It might be useful to have the UI that guides people to crop to the aspect ratio the site prefers, but most sites are somewhat imprecise about the entire concept anyway. (E.g. Facebook's profile photo layout has changed a number of times over the years. When I worked on the Photos team there, effort was being put into trying to automatically generate crops of photos so they could be display in a variety of places with different aspect ratios due to design choices. That this would enrage any serious photographer was not a significant concern to those working on the feature.)
It also takes a moderate amount of design and programming to do the UI for this and thus it doesn't get done that often. But most likely the reason is because it confuses users. Instagram would be an exception as it heavily pushes toward square aspect ratio and its large user base has very much embraced this. The UI very much steers one to crop to a square.

Related

In GIMP (DBP), how can I batch-resize photos to a certain width and keep aspect ratio?

I have been using GIMP to resize photos one by one, to say 800px-width while keeping aspect ratio. I downloaded the David Batch Processor plugin and everything looks fine, except it isn't able to resize to a predetermined width or height whilst keeping the aspect ratio.
Relative: I can resize by % and keep aspect ratio, but the photos are of different sizes and orientation, so no one % works.
Absolute: There isn't an option to keep aspect ratio, and no one height works for all photos.
Can someone please advise if there is a way to batch-resize photos of different original sizes using GIMP's dbp or there is some other plugin that can work?
I realised that for whatever reason, that Dbp just doesn't have the function to keep the aspect ratio in absolute resizing, so either I write a script from scratch which is an overkill for my purpose or find another plugin for batch processing. I am now using one called Batch Image Manipulation. https://alessandrofrancesconi.it/projects/bimp/

Using an image as a background of a UIViewController and supporting multiple screen sizes

On some view controllers I am using images as background for the whole screen. I was wondering what is the best practice for this, since I want to support all currently available iPhones (5-7). Normally for images I would get #2x and #3x image, but here the case is a little bit different?
Do I add 4 photos to app and then ask system on which device i am running and than load appropriate photo? This seems kinda clunky, an not really elegant.
You don't really have that many options.
You could bundle different images for the different device aspect ratios, check the device aspect ratio at runtime, and load the correct image. This implementation is flawed, as it doesn't account for future device aspect ratios. You could have a webservice which returns a correct image for a given aspect ratio, to take that work off of the client.
You could also create a single image that looks good on all device sizes, and load the image into a UIImageView and set its contentMode UIViewContentMode.scaleAspectFill to fill the entire image into the view's frame, cropping some portion of the top, bottom, or sides out.
I've solved this in my projects by using the 'xcassets'. The system basically takes care of the 'which device size' question for you. Also, play around with the differing contentMode properties (i.e.'aspectFit', 'aspectFill', 'scaleToFill').
Another thing I would watch out for is the value for 'autoResizingMask' property. In most cases if my sizing isn't doing what I think it should, I check if I gave autoResizingMask a value of 'No'.
I hope this helps!

xcode image size isn't consistent through ios models

I am aware this question must have been asked before, but after 2 hours of searching and failure to find a working answer, I decided to ask again.
As you all know, each iOS model has a different screen size. However when I insert my logo (or any image) into my app, it maintains a specific size for whatever iOS model I preview it in, therefore it is too small on the 6+, yet doesn't fit on the screen on the 4.
Using code or not, how can I make my images be the same scale on each iOS model?
To achieve what you are asking for you can just use Constraints throughout your project. The easiest way would probably be to just make an aspect ratio constraint on your image view. However that will only keep the ratio of width to height the same. In order to make it fit onto all the screens, you should simply add some constraint to your image view, as for example trailing space to container margin. You can set those through here:
If you set for example 0,0,0 then this will keep your logo in the upper part of yur screen and always fitting into the screen. You may also want to consider adding a height constraint, so your logo doesn't get compressed.
Hope that helps,
Julian
Within your image casset you need to have an #3x and an #2x, then it will choose the right image size for the right device.

UIImage size managment

I have an image that is used in multiple places within my IOS app at various sizes. Should I be using one large image in conjunction with UIViewContentModeScaleAspectFit to scale it (currently this approach seems to cause distortion on the smaller images despite being scaled to proportionate sizes) or should I have multiple versions of the image at different sizes.
It seems a little extreme to have so many copies of one image e.g. my_image_ipad, my_image_small, my_image_large, my_image_medium.
In general it depends on what it takes to get the look and quality you want. Some images will scale from a large image to a small image with little or no visual loss in quality. Others, as you've found, scale poorly, especially at extreme scales. You're really going to have to just try various solutions and see what works. One way you can almost always cut down on application size is to remove the non-#2x artwork and ship with just the #2x.
It is better to use one image, because it will make your app "lighter", but this may cause your code to become bigger.

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.

Resources