Skip to content

Content-scaled image manipulation #444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jlooper opened this issue Jul 15, 2015 · 16 comments
Closed

Content-scaled image manipulation #444

jlooper opened this issue Jul 15, 2015 · 16 comments

Comments

@jlooper
Copy link

jlooper commented Jul 15, 2015

Currently, to support content scaling, the developer is obliged to create three images, like img.png, img@2x.png, and img@3x.png in a gradation of sizes to be handled by small, medium, and hi-res screens. NativeScript is great about taking the images that you add to your app and placing them in the proper folders for iOS. For Android, I believe we have to rename them move them manually, as described here: http://nativescript.github.io/quick-start/#chapter2.4.

This seems pretty labor-intensive. Could NativeScript's build process take a large image, scale it down 2x and 1x, and add them to the proper folders automatically for iOS and Android? It seems like we're almost there, we just need to tweak the build process.

We think this will help onboard web developers, who don't love manually rescaling images and pasting them everywhere :)

@tjvantoll
Copy link
Contributor

+1

When you want to show an image in an app, to me there are two ways to go about that:

    1. You want to take advantage of the extra pixel density and create different images for different device types—aka your img@2x.png is not just a straight resize of img@3x.png.
    1. You want to show the same image on devices of all pixel densities.

What's currently implemented in {N}, and what we have documented here, is great for scenario #1.

For for scenario #2, which I would guess is far more common, having to create 6 images—AppResources/iOS/img.png, AppResources/iOS/img@2x.png, AppResources/iOS/img@3x.png, App_Resources/Android/drawable-hdpi/img.png, App_Resources/Android/drawable-mdpi/img.png, and App_Resources/Android/drawable-ldpi/img.png—is indeed labor intensive as @jlooper says. It'd be great if the NativeScript CLI (or the modules, if possible), provided some solution for images to look great from a single source.

@valentinstoychev
Copy link

Isn't #2 ugly? Why no use automation to create the images and use #1?

@emiloberg
Copy link

Reason to do it the #1 way is simple:

Example: High pixel density screens allows us to create high def images with lots of fine details, however, when that image is displayed on a lower pixel density screen it might become kinda ugly. Therefor we need to remove/rework some of the details for lower density screens.

But, what we need is a way to do both #1 and #2.

@jlooper
Copy link
Author

jlooper commented Jul 17, 2015

Personally I wouldn't worry about #2, as it's not the normal 'mobile' way to develop - we are used to making two or three versions of our images to satisfy iPhone4 as well as hi-res iPads. I'd just love to have {N} have a built-in way to content scale. It would give us a leg up on the competition. For example, the Appcelerator docs tell you flat out to optimize your own images:

http://docs.appcelerator.com/platform/latest/#!/guide/Image_Best_Practices-section-30082525_ImageBestPractices-Optimizingimages

If we can't help with the actual optimization, what if we allowed users to put the three scaled images into a location and then {N} build process places them, renamed appropriately, into the right folder for the platform?

@tjvantoll
Copy link
Contributor

@jlooper and I talked this over. Our ideal structure is something like what's shown below. There'd be some special folder where you put all of your app's images in (app/images or whatever), using some convention to designate three different pixel densities.

app
    images
        1x
            logo.png
        2x
            logo.png
        3x
            logo.png

The NativeScript CLI could take all images, and move them to the appropriate places in App_Resources. For instance with the above example, app/images/base/3x/logo.png would move to App_Resources/iOS/logo@3x.png and App_Resources/Android/drawable-hdpi/logo.png. This provides a solution to #2.

If the user only provides a 3x image, in theory, the CLI should automatically be able to generate the 1x and 2x versions automatically. This extra bit of logic would provide a solution to #1.

Obviously implementing this would be a bit of work, and there are potentially some performance implications, but if you read through what you currently have to do to use correctly scaled images, I do think it's a bit much, and it'd be nice to have something easier to use longterm.

@emiloberg
Copy link

I'm touching scope creep here but a nice addition would be to be able to supply SVGs which gets converted to pngs (of all sizes). Pretty much what I'm doing in this gulp script.

But as said, scope creep and maybe not at top of the priority list.

@ligaz
Copy link
Contributor

ligaz commented Oct 13, 2015

Hey guys,

Have you played with appbuilder resource create command? Do you think if we extend its usage to support arbitrary images (not only icons and splashes) is the way to go?

@jlooper
Copy link
Author

jlooper commented Dec 4, 2015

late to reply, but if we could run our images through some builder and scale everything, renamed appropriately, and stuck in the right folder, my life would be complete :)

@enchev
Copy link
Contributor

enchev commented Aug 8, 2016

Hey folks,

Do you think we still need this?

@tjvantoll
Copy link
Contributor

tjvantoll commented Aug 8, 2016

@enchev: I initially supported doing this, and still think something like this might be nice. But since this issue was first created the Brosteins built http://nsimage.brosteins.com/, and that tool simplifies the manual work to create these images considerably.

So, my vote is to close this unless there’s additional community demand, especially as there have been zero comments in the last eight months.

@enchev
Copy link
Contributor

enchev commented Aug 8, 2016

Thanks @tjvantoll! I'll close it for now.

@enchev enchev closed this as completed Aug 8, 2016
@julien1619
Copy link

Hi! I'm starting to develop a new project using NativeScript and I didn't find any way to automate the images generation process. So I've created a hook that you can install in your project and it will automatically generate all needed images.

https://www.npmjs.com/package/nativescript-images-generator-hook

I'm sharing it here because I think it could be very useful.

@NathanaelA

This comment was marked as abuse.

@julien1619
Copy link

@NathanaelA Thanks! Yes I saw these solutions but I needed a way to automate the full process so using a webservice was not an option. Moreover, with this hook you have to commit only one high-res image per resource, the other ones are generated during the build process directly inside the right platform folder.

@NathanaelA

This comment was marked as abuse.

@lock
Copy link

lock bot commented Apr 18, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Apr 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants