Code Monkey home page Code Monkey logo

compressor's People

Contributors

aftabsikander avatar hbarnardt avatar kawmra avatar ludejin avatar muhrifqii avatar paolorotolo avatar rakesh4a7 avatar subhrajyotisen avatar vpop avatar zetbaitsu 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

compressor's Issues

Returned 0 bytes file

Hi,
I used custom compressor (same as given in your example) but it returned an image of 0 bytes.
When i removed .setDestinationDirectoryPath(Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES).getAbsolutePath())
It worked! I am using android 4.4.2
What can be the possible reasons for this?
Thanks

Update Documentation

You should probably mention that the library also does a Rotate on the image during the rescale process.
The library also catches any exception possible (OOM, ...) it makes it quite hard to debug when using it.

How to encodeTobase64?

Hi i use the Compressor and after i need to encodeTobase64. I think i´m compress the image twice times. How could i encondetobase64 without compress two times? :

bitmap = new Compressor.Builder(getContext())
.setMaxWidth(940)
.setMaxHeight(780)
.setQuality(85)
.setCompressFormat(Bitmap.CompressFormat.PNG)
.build()
.compressToBitmap(imgFile);

String photoBase64 = encodeTobase64(bitmap);

And here receive to encodetobase64:

public static String encodeTobase64(Bitmap image) {
Bitmap bitmap = image;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
byte[] b = baos.toByteArray();
String imageEncoded = Base64.encodeToString(b, Base64.DEFAULT);
return imageEncoded;
}

Thank you!

(Doubt) Tool for Node

Hi, I use this library a few years ago.
And works very well.

Do you think to do in NodeJs?
ty

decodeFile issues

I want to know :With the "Factory. DecodeFile ()" compression many very large images, will outofmemeryError?

Type of compression

Which type of compression is there, is it lossless or lossy?
And can can we compress image in WEBP format?

Thanks

EXIF

Does this keep the exif information from the original file? Like rotation on some Samsung devices?

code meaning

what is meaning of
if (bmp == null) { InputStream inputStream = null; try { inputStream = new FileInputStream(filePath); BitmapFactory.decodeStream(inputStream, null, options); inputStream.close(); } catch (FileNotFoundException exception) { exception.printStackTrace(); } catch (IOException exception) { exception.printStackTrace(); } }
why add that after Bitmap bmp = BitmapFactory.decodeFile(filePath, options);

Better Exceptions

when there is no storage permission to read/write. better through the exception stating

  1. no READ_STORAGE permission
  2. no WRITE_STORAGE permission => no access to that directory

in current version this library is throwing "width and height must be > 0" which is not correct

java.lang.IllegalArgumentException: width and height must be > 0

java.lang.IllegalArgumentException: width and height must be > 0
at android.graphics.Bitmap.createBitmap(Bitmap.java:967)
at android.graphics.Bitmap.createBitmap(Bitmap.java:946)
at android.graphics.Bitmap.createBitmap(Bitmap.java:913)
at id.zelory.compressor.ImageUtil.getScaledBitmap(ImageUtil.java:116)
at id.zelory.compressor.ImageUtil.compressImage(ImageUtil.java:161)
at id.zelory.compressor.Compressor.compressToFile(Compressor.java:48)

receiving in

DEVICE config

Android 6.01
Family samsung
Model on7xeltedd (SM-G610F)
Architecture armv8l
Orientation portrait
screen_resolution 1920x1080

width and height > 0 Exception, on correct path

I have double checked the file I'm using for compressToFile() is indeed an image file. I have succeeded using the exact same file for uploading it as is.

Though compressToFile() throws an
java.lang.IllegalArgumentException: width and height must be > 0`

This is the calling function

File compressedFile = Compressor.getDefault(this).compressToFile(new File(uri));
Where uri is a string representing the location.

How to make a proguard with this lib ?

I'm build the APK using proguard, and it says that I've to make some proguard config using your library. Could you explain me how to add a proguard config for your lib ?

Context Leak

Distinctly, context leak

    private static volatile Compressor INSTANCE;
    private Context context;

Force output size or minimum size option

My application have to compress image to defined size (1080 * 1080)
Even the original image size is smaller than desired size I have to scale it to large resolution.
So it would be nice if it has "Force size" or "Minimum size" option.
Thanks.

Add ability to set up Bitmap Config

Currently library uses Bitmap.Config.ARGB_8888 for creating bitmap. I want to use, for example Bitmap.Config.RGB_565. How I can achieve that?

Or, if not, could you please provide setter in Builder to have ability to choose Bitmap.Config for my aims?

replace file

how replace original file with new compress file.?

Upgrade to RxJava2.0.1

my project use RxJava2.0.1, and i use this lib to handler image,.
Then when i run my project like this:
Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.

com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/rxjava.properties
File1: /Users/envative/.gradle/caches/modules-2/files-2.1/io.reactivex/rxjava/1.1.6/2586312cd2b8a511e4c6236736f5a039fc0f2273/rxjava-1.1.6.jar
File2: /Users/envative/.gradle/caches/modules-2/files-2.1/io.reactivex.rxjava2/rxjava/2.0.1/57f850a6b317e5582f1dbaff10a9e7d7e1fcdcfb/rxjava-2.0.1.jar

geting java.lang.IllegalArgumentException when the name of the image is less than 3 characters at the time of image selection from gallery

Below is the log

FATAL EXCEPTION: main
Process: com.yellowpages.et.directory, PID: 30682
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=content://com.android.providers.media.documents/document/image:6263 flg=0x1 }} to activity {com.yellowpages.et.directory/com.yellowpages.et.directory.Activities.NewPostActivity}: java.lang.IllegalArgumentException: prefix must be at least 3 characters
at android.app.ActivityThread.deliverResults(ActivityThread.java:4672)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4715)
at android.app.ActivityThread.access$1500(ActivityThread.java:198)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1725)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6837)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: java.lang.IllegalArgumentException: prefix must be at least 3 characters
at java.io.File.createTempFile(File.java:996)
at java.io.File.createTempFile(File.java:966)
at id.zelory.compressor.FileUtil.from(FileUtil.java:38)
at com.yellowpages.et.directory.Activities.NewPostActivity.onActivityResult(NewPostActivity.java:175)
at android.app.Activity.dispatchActivityResult(Activity.java:6758)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4668)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4715) 
at android.app.ActivityThread.access$1500(ActivityThread.java:198) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1725) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:145) 
at android.app.ActivityThread.main(ActivityThread.java:6837) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199) 

The <application> tag in `mainfest.xml in the library might be unnecessary

The code below in the libary's manifest.xml is unnecessary and make mistake

<application android:allowBackup="true" android:label="@string/app_name" android:supportsRtl="true" > </application>

When I build gradle, it will tell me the

Attribute application@label value=(@string/application_name) from AndroidManifest.xml:30:9 is also present at {id.zelory:compressor} value=(@string/app_name) Suggestion: add 'tools:replace="android:label"' to <application> element at AndroidManifest.xml:26:5 to override

When I follow the direction I fix this error, however I think maybe removing the tag from library is a better solution for others.

Compressed file not getting deleted from external storage

Below is how I'm using the compression of image taken from camera intent
final File compressedOutput1 = new Compressor.Builder(getApplicationContext()) .setMaxWidth(1024) .setMaxHeight(768) .setQuality(75) .setCompressFormat(Bitmap.CompressFormat.JPEG) .setDestinationDirectoryPath(Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES).getAbsolutePath()) .build() .compressToFile(output1);

And after the compression this file is uploaded to server, and I'm deleting the file using
File fDelete2 = FileUtils.getFile(mContext, Uri.fromFile(compressedOutput1)); if (fDelete2.exists()) { if (fDelete2.delete()) { Toast.makeText(mContext, "Upload complete, Local copy of uploaded file has been deleted", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(mContext, "Could not delete file", Toast.LENGTH_SHORT).show(); } }

But when I'm checking the external storage pictures directory, the file exists there.
Why delete() not worked?
Please help.

I use the custom Compressor style,but throw "java.lang.NullPointerException"

I'm using for the example:
new Compressor.Builder(this)
.setMaxWidth(320)
.setMaxHeight(640)
.setQuality(75)
.setCompressFormat(Bitmap.CompressFormat.JPEG)
.setDestinationDirectoryPath(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES).getAbsolutePath())
.build()
.compressToFile(new File("my file path"));

when the code execute to "compressToFile",throw the NullPointerException,My file path is exist, I want to know why?(On Android 4.4.2 occurred,Android 5.0 or 6.0 is ok!)

Fatal Exception: java.lang.OutOfMemoryError

   at dalvik.system.VMRuntime.newNonMovableArray(VMRuntime.java)
   at android.graphics.Bitmap.nativeCreate(Bitmap.java)
   at android.graphics.Bitmap.createBitmap(Bitmap.java:831)
   at android.graphics.Bitmap.createBitmap(Bitmap.java:808)
   at android.graphics.Bitmap.createBitmap(Bitmap.java:728)
   at id.zelory.compressor.ImageUtil.getScaledBitmap(ImageUtil.java:144)
   at id.zelory.compressor.ImageUtil.compressImage(ImageUtil.java:161)
   at id.zelory.compressor.Compressor.compressToFile(Compressor.java:47)

Should accept Uri as well

It should also accept Uri as a parameter. I tried converting my Uri into file and then passed it. It shows error "Image not found". Another line was saying "image width and height should not be less than 0".

Library shouldn't crash if someone is passing bad file. It should be capable to handle the same if it suggests possible root cause then that would be appreciable.

error

java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
at id.zelory.compressor.ImageUtil.getScaledBitmap(ImageUtil.java:96)
at id.zelory.compressor.ImageUtil.compressImage(ImageUtil.java:128)
at id.zelory.compressor.Compressor.compressToFile(Compressor.java:43)
at com.rxjr.rxcd.beta.utils.CompressUtil.doInBackground(CompressUtil.java:48)
at com.rxjr.rxcd.beta.utils.CompressUtil.doInBackground(CompressUtil.java:21)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)

Upgrade to RxJava 2.0.1

I am using RxJava 2.0.1 in my project and when i import Compressor it wont compile complaining i have multiple versions of RxJava.

Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/rxjava.properties
  	File1: /Users/envative/.gradle/caches/modules-2/files-2.1/io.reactivex/rxjava/1.1.6/2586312cd2b8a511e4c6236736f5a039fc0f2273/rxjava-1.1.6.jar
  	File2: /Users/envative/.gradle/caches/modules-2/files-2.1/io.reactivex.rxjava2/rxjava/2.0.1/57f850a6b317e5582f1dbaff10a9e7d7e1fcdcfb/rxjava-2.0.1.jar

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.