Git Product home page Git Product logo

res-resizer's Introduction

Welcome

Res Resizer is a script that allows you to automatically process resource files for both Android and iOS projects.

For both iOS and Android you can process an individual file or an entire folder. There are subtle differences between the way the script handles resources for different projects.

The script will process PNG and JPG files. It ignores NinePatch files.

iOS

If you point the script at a folder, the script will process only images that contain the @2x modifier in the file name. All other image files remain untouched. This prevents us from shrinking specific files for the 4" retina screen. The files are outputted in the same directory with the @2x omitted from the new file name. Keep in mind this overwrites any existing file with that file name.

Android

For 0.4.0 I have eliminated outputting images for the ldpi density. The Android documentation no longer lists this as a requirement.

Point the script at your xxhdpi drawables folder and the script will process either an individual file, or the entire folder, and output your xhdpi, hdpi, and mdpi resources in their respective folders. If these folders don't exist the script will create them for you.

Android Example

Point the script at "res/drawables-xxhdpi", which the script assumes contains your xxhdpi images. Should your folder for the lower quality images not exist, the script will create the folders for you. You will end up with:

  • res/drawables-xxhdpi/
  • res/drawables-xhdpi/
  • res/drawables-hdpi/
  • res/drawables-mdpi/

Usage

$ chmod +x resizer.py Makes the script runnable.

Hint: all output can be silenced by adding the --silence option.

iOS

$./resizer.py -i --folder ~/MyProject/project/images/ resize all images in the images folder of your project.

$ ./resizer.py -i --file ~/MyProject/project/images/my_image.png resize only one specific image.

Android

$./resizer.py -a --folder ~/MyProject/res/drawables-xxhdpi resize all found images in xxhdpi folder. Script will output in Android style.

$ ./resizer.py -a --file ~/MyProjects/res/drawables-xxhdpi/my_image.png resize specific image only.

$ ./resizer.py -a --prod automatically find xxhdpi folder and execute as with --folder option. Note: --prod does not work with iOS flag.

$ ./resizer.py --exclude-scale [mdpi|hdpi|xhdpi] do not scale down to this density. Exclude multiple at once: --exclude-scale ldpi mdpi.

Feedback & Improvements

Please, let me know what can be improved. Fork it!

res-resizer's People

Contributors

jlindenbaum avatar tskulbru avatar wuchiang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

res-resizer's Issues

Add support for xxhdpi

Add support for new XXHDPI (480dpi) which is 1.5x XHDPI.

Determine if this should replace XHDPI as default folder, or wait for more devices/adoption. If it does not replace default behaviour a flag should be created that allows execution from within xxhdpi folder, rather than xhdpi.

Discussion - MSIE / Android / iOS Icons

Summary

  • I'd like to add support for MSIE tile generation.
  • I'm unsatisfied with the current argument flags, and how they're setup, I'm looking to change things, and would appreciate some feedback. I'm hoping that the new argument structure keeps the power of the script, and leaves it flexible enough to add new platforms and options going forward.

I want to make sure that the new structure of arguments doesn't ruin everyone's workflow, just because it suits mine.

Proposal for MSIE

In recent weeks I've noticed more and more requests to browserconfig.xml creeping up in our access logs, and would like to add support for MSIE into the resizer. An icon should be resized into all the arguments provided by MSIE to make Windows 8 / Windows Phone 7&8 tiles for IE10 and 11.

More about this here: http://msdn.microsoft.com/en-us/library/ie/dn320426(v=vs.85).aspx

New argument structure

Usually my workflow for icon generation comes after the designers have decided that the icon works at anything from 50x50 to 1024x1024. I receive the 1024x1024 and just want to run it through the script and have it spit everything out for me. Regardless of Android, or iOS.

In the following examples any instance of --file can be replaced with --folder. So either an individual file, or an entire folder would be processed.

I'm unhappy with the interaction of the -i and -a flags and their interaction with --app-icon and --pngconv. I don't think I thought those through enough when I created them, and now it's a bit messy.

Right now...

  • ... to to format a JPG to a PNG, you have to specify -a or -i which is absurd, as the PNG conversion can be done regardless of iOS or Android resizing logic.
  • ... to generate iOS app icons, you have to specify -i --app-icon --file which are too many arguments for a simple app icon resize.
  • ... the -prod argument is very android specific.

New argument structure

Platform agnostic flags

  • PNG Convert: This would include --pngconv. Any file specified with --file can be converted to PNG, regardless of platform. The new way to convert an image to PNG, would be: --pngconv --file /my-jpg.jpg
  • New: Resize any image to any size: --resize wxh. A new flag that would you resize any file specified with --file to the provided width x height dimensions. The way to resize any image would be: --resize 300x300 --file /my_1024x1024.png.

iOS flags

  • All iOS related arguments would be prefixed with --ios for clarity.
  • To resize an @2x image it would now be --ios --file [email protected] which would output image.png into the same directory.
  • To generate all app icons it would now be --ios-app-icon --file app_icon_1024x1024.png which would output all app icons, spotlight, settings, toolbar, etc. sizes as it currently does into the same directory.
  • New: Generate web clip icons --ios-webclip-icons --file app_icon_1024x1024.png which would output web clip icons for iOS7 and above. Useful for web developers allowing users to shortcut their sites with nice icons.

Android flags

  • All Android related arguments would be prefixed with --android for clarity.
  • Creating application icons should be done in a similar way to iOS, where we can point the script at any large file, and have it spit out any density. I propose the sizes be calculated from the mdpi baseline of 48x48 dp. Thus --android-app-icon --file app_icon_1024x1024.png would result in mdpi of 48x48, hdpi of 72x72, xhdpi of 96x96, etc. As all scales going up (xxhdpi, xxxhdpi, xxxxhdpi) are just multiples of the baseline, this can easily future proof for any more higher densities added into the SDK.
  • Resizing Android images as before would now be --android --file drawable-xxxxhdpi/image.png and it would resize into all scales, unless excluded with --exclude-scale.
  • The --prod flag would be replaced with --android-prod, but function the same way.

MSIE flags

  • New: Completely new resizing class that could accept a default 1024x1024 icon, and resize it to the square icons defined in the MSIE Browser Config document (http://msdn.microsoft.com/en-us/library/ie/dn320426(v=vs.85).aspx). This would be run with --ms-browserconfig --file app_icon_1024x1024.png and have it return the square options defined in the document. This would not handle the 310x150 case in its first iteration. Note: This is intended for browsers. I do not know enough about Windows 8 development to know all the required icon sizes for desktop / phone development. If anyone has any insights, feel free to share in a comment.

Thanks in advance for any feedback given, and hope this will improve the script going forward. Thanks to everyone who has contributed, and uses the script.

ImportError: No module named Image

I'm getting

Traceback (most recent call last):
File "/usr/bin/android-res-resize.py", line 15, in
import Image
ImportError: No module named Image

could someone help me?

Add scaling options

Ability to exclude certain scales from being processed.
Something like --exclude-scale ldpi

add default path , so I can use this more easy

if args.folderPath == None:

    from os.path import join, dirname, abspath, exists
    folderPath = join(dirname(abspath(__file__)),"res/drawable-xhdpi")
    if exists(folderPath):
        args.folderPath = folderPath 

Ability to convert file or folder to PNG

Arguments:

  • --pngconv --file ~/path/to/file.jpg
  • --pngconv --folder ~/path/to/folder/

Convert accepted file extensions (right now JPG) and convert them to PNG. This will rename a file as well. image.jpg will turn into image.png.

--prod uses absolute instead of relative path

When using --prod option it's assumed the script is in the android project. Would it make more sense to have it as a path relative to current working directory?

~/code/myproject/ $ ~/tools/android-res-resize.py --prod will fail, as ~/tools/ does not have a res/ directory.

I am assuming that --prod could be run from anywhere (easier if it's in $PATH) but would run --prod from current working directory.

~/code/myproject/ $ ~/tools/android-res-resize.py --prod would work as ~/code/myproject/ has res/ folder in it.

What's expected behaviour?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.