An image resizing library for Android

Overview

Resizer

Android Arsenal

Inspired by zetbaitsu's Compressor, Resizer is a lightweight and easy-to-use Android library for image scaling. It allows you to resize an image file to a smaller or bigger one while keeping the aspect ratio.

Include Resizer into your project

  1. Add the JitPack repository to your top-level build.gradle at the end of repositories
allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}
  1. Add the dependency in your module-level build.gradle
dependencies {
    compile 'com.github.hkk595:Resizer:v1.5'
}

Pass in the original image file and get the resized image as a new file

File resizedImage = new Resizer(this)
        .setTargetLength(1080)
        .setQuality(80)
        .setOutputFormat("JPEG")
        .setOutputFilename("resized_image")
        .setOutputDirPath(storagePath)
        .setSourceImage(originalImage)
        .getResizedFile();

Pass in the original image file and get the resized image as a new bitmap

Bitmap resizedImage = new Resizer(this)
        .setTargetLength(1080)
        .setSourceImage(originalImage)
        .getResizedBitmap();

Note: You only need to specify the target length (in pixel) of the longer side (or either side if it's a square) of the image. Resizer will calculate the rest automatically.

Using RxJava 2 with RxAndroid to get the resized image asynchronously

final File[] resizedImage = new File[1];
new Resizer(this)
        .setTargetLength(1080)
        .setQuality(80)
        .setOutputFormat("JPEG")
        .setOutputFilename("resized_image")
        .setOutputDirPath(storagePath)
        .setSourceImage(originalImage)
        .getResizedFileAsFlowable()
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe(new Consumer<File>() {
            @Override
            public void accept(File file) {
                resizedImage[0] = file;
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) {
                throwable.printStackTrace();
            }
        });
final Bitmap[] resizedImage = new Bitmap[1];
new Resizer(this)
        .setTargetLength(1080)
        .setSourceImage(originalImage)
        .getResizedBitmapAsFlowable()
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe(new Consumer<Bitmap>() {
            @Override
            public void accept(Bitmap bitmap) {
                resizedImage[0] = bitmap;
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) {
                throwable.printStackTrace();
            }
        });

Note: You don't need to declare the new image as final nor array if it's an instance variable of the class, instead of a local variable in a function.

Refer to the JavaDoc for more details.

Library specification

Minimum SDK: API 16
 
Default settings:
targetLength: 1080
quality: 80
outputFormat: JPEG
outputFilename: same as the source file
outputDirPath: the external files directory of your app
 
Supported input formats:
BMP
GIF
JPEG
PNG
WEBP
 
Supported output formats:
JPEG
PNG
WEBP
 
Supported quality range: 0~100
The higher value, the better image quality but larger file size
PNG, which is a lossless format, will ignore the quality setting

License

MIT License
 
Copyright (c) 2017 K.K. Ho
 
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
 
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
 
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Comments
  • [Feature request] Please add support to API 16

    [Feature request] Please add support to API 16

    I found this library to be one of the best available out there (to use with Rx), but sadly I can't use it just because I need to support API 16. Are there any issues that prevent pre-21 APIs to be supported?

    Thank you!

    opened by patrickpissurno 1
  • me.echodev.resizer.util.ImageUtils.getScaledBitmap

    me.echodev.resizer.util.ImageUtils.getScaledBitmap

    The exception could not be delivered to the consumer because it has already canceled/disposed the flow or the exception has nowhere to go to begin with. Further reading: https://github.com/ReactiveX/RxJava/wiki/What's-different-in-2.0#error-handling | java.lang.OutOfMemoryError: Failed to allocate a 3464652 byte allocation with 3291992 free bytes and 3MB until OOM at io.reactivex.plugins.RxJavaPlugins.onError(RxJavaPlugins.java:2) at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java) at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:154) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) at java.lang.Thread.run(Thread.java:818)

    opened by darwish1994 0
  • Animated webp not animating after resize.

    Animated webp not animating after resize.

    I tried resizing animated webp but the result webp is not animating.

    val resizedImage = Resizer(this) .setTargetLength(512) .setQuality(100) .setOutputFormat("WEBP") .setOutputFilename("result") .setOutputDirPath(outputPath) .setSourceImage(File(inputPath)) .resizedFile

    opened by nsiva7 1
  • Manifest merger failed

    Manifest merger failed

    : Attribute application@supportsRtl value=(false) from AndroidManifest.xml:23:9-36
    	is also present at [com.github.hkk595:Resizer:v1.5] AndroidManifest.xml:14:9-35 value=(true).
    	Suggestion: add 'tools:replace="android:supportsRtl"' to <application> element at AndroidManifest.xml:15:5-68:19 to override.
    

    Right now I use tools:replace="android:supportsRtl" as workaround.

    opened by hydrated 0
  • Simply doesn't work

    Simply doesn't work

    Here's a module for compressor

    @Module
    class CompressorModule {
        @Provides
        @Singleton
        fun provideCompressor(context: Context) = Resizer(context)
                .setTargetLength(1000)
                .setQuality(75)
                .setOutputFormat("JPEG")
                .setOutputFilename(UUID.randomUUID().toString())
                .setOutputDirPath(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES)!!.absolutePath)
    }
    
    

    And here's how we use it:

     override fun uploadImage(file: File): Single<Image> =
                file.run {
                    System.out.println("Pre compressor size: ${file.totalSpace}")
                    resizer
                            .setSourceImage(file)
                            .resizedFileAsFlowable
                            .subscribeOn(Schedulers.io())
                            .singleOrError()
                            .flatMap { compressedFile ->
                                System.out.println("Post compressor size: ${compressedFile.totalSpace}")
                                Single.fromCallable {
                                    defaultApi.v2ImagesPost(compressedFile)
                                }
                            }
                }
    

    And here's result of compression:

    I/System.out: Pre compressor size: 57986539520
    I/System.out: Post compressor size: 57986539520
    

    Thus, nothing has changed: not size, not file resolution (which is twice the size specified). What are we doing wrong?

    opened by egorikem 1
Owner
Kakit Ho
A computer engineer who likes to explore new technologies.
Kakit Ho
This is an Image slider with swipes, Here we used Volley to Image load URL's from JSON! Here we make it very easy way to load images from Internet and We customized the description font style(OpenSans).

ImageSliderWithSwipes This is an Image slider with swipes, Here we used Volley to load URL's from JSON! Here we make it very easy way to load images f

Prabhakar Thota 44 May 31, 2021
An android image compression library.

Compressor Compressor is a lightweight and powerful android image compression library. Compressor will allow you to compress large photos into smaller

Zetra 6.7k Dec 31, 2022
A simple image cropping library for Android.

SimpleCropView The SimpleCropView is an image cropping library for Android. It simplifies your code for cropping image and provides an easily customiz

Issei Aoki 2.5k Dec 28, 2022
Customizable Android full screen image viewer for Fresco library supporting "pinch to zoom" and "swipe to dismiss" gestures. Made by Stfalcon

This project is no longer supported. If you're able to switch from Fresco to any other library that works with the Android's ImageView, please migrate

Stfalcon LLC 1.8k Dec 19, 2022
Dali is an image blur library for Android. It contains several modules for static blurring, live blurring and animations.

Dali Dali is an image blur library for Android. It is easy to use, fast and extensible. Dali contains several modules for either static blurring, live

Patrick Favre-Bulle 1k Dec 1, 2022
Simple android image popup Library

Android Image Popup Show image as a popup on a click event or any event. Simply set the image as drawable and thats it!!!. And also you can set width,

Chathura Lakmal 64 Nov 15, 2022
Image loading library for Android

Image Loader Image loader library for Android. Deprecated. See Glide. Features Image transformations Automatic memory and storage caching Ability to l

Yuriy Budiyev 19 May 28, 2022
Image Cropping Library for Android, optimised for Camera / Gallery.

Image Cropping Library for Android, optimised for Camera / Gallery.

CanHub 812 Dec 30, 2022
An image loading library for android.

Bilder Download Add following to your project's build.gradle allprojects { repositories { ... maven { url 'https://jitpack.io' } } }

Kshitij Sharma 4 Jan 1, 2022
An Android transformation library providing a variety of image transformations for Coil, Glide, Picasso, and Fresco.

An Android transformation library providing a variety of image transformations for Coil, Glide, Picasso, and Fresco.

Daichi Furiya 257 Jan 2, 2023
🎨 Modern image loading library for Android. Simple by design, powerful under the hood.

Simple Image Loader Modern image loading library for Android. Simple by design, powerful under the hood. Kotlin: Simple Image Loader is Kotlin-native

Igor Solkin 8 Nov 21, 2022
Image Cropping Library for Android

Image Cropping Library for Android

Lyrebird Studio 1.1k Dec 30, 2022
A small customizable library useful to handle an gallery image pick action built-in your app. :sunrise_over_mountains::stars:

Louvre A small customizable image picker. Useful to handle an gallery image pick action built-in your app. *Images from Google Image Search Installati

André Mion 640 Nov 19, 2022
Library to save image locally and shows options to open and share !

Image Save and Share Library to save image locally and shows options to open and share ! Download Demo APK from HERE Kindly use the following links to

Prabhakar Thota 27 Apr 18, 2022
RoundedImageView-Library 0.9 0.0 Java To set single or multiple corners on Image Views.

RoundedImageView-Library Rounded ImageView Android Library, to set single or multiple corners on imageview. Screenshot Usage Step 1. Add the JitPack r

Dushyant Mainwal 15 Sep 2, 2020
A library for image manipulation with power of renderScript which is faster than other ordinary solutions.

Pixl is a library for image manipulation with power of renderScript which is faster than other ordinary solutions, currently it includes three basic scripts, brightness, contrast, saturation.

Jibran Iqbal 20 Jan 23, 2022
Image cropping library written with Jetpack Compose with other Composables such as ImageWithConstraints scales Bitmap

Image cropping library written with Jetpack Compose with other Composables such as ImageWithConstraints scales Bitmap it displays and returns position and bounds of Bitmap and ImageWithThumbnail to display thumbnail of the image on selected corner.

Smart Tool Factory 9 Jul 27, 2022
Phimp.me Android Phimp.me is an Android image editor app

Phimp.me Android Phimp.me is an Android image editor app that aims to replace proprietary photographing and image apps on smart phones. It offers feat

FOSSASIA 2.6k Jan 6, 2023
some android image filters

android-image-filter some android image filters in some filter, I use NDK to implement to make it more efficient Setup Install Android NDK and properl

RagnarokStack 643 Dec 27, 2022