Giter Site home page Giter Site logo

phonegap-image-resizer's Introduction

  • NOTE - I am sorry, I just can't find the time to fully test the plugin and develop it further. Small updates are constantly integrated. *

Image Resizer plugin for Phonegap/Cordova 3.0+

This plugin resizes images natively using the phonegap / cordova architecture.

Adding the Plugin to your project

The plugin conforms to the Cordova plugin specification, it can be installed using the Cordova / Phonegap command line interface.

phonegap plugin add https://github.com/RaananW/PhoneGap-Image-Resizer

cordova plugin add https://github.com/RaananW/PhoneGap-Image-Resizer

Using the plugin

The plugin creates the object window.imageResizer. window.plugins.imageResizer still works for older versions.

To use, call one of the following, available methods:

   window.imageResizer.resizeImage(successCallBack, failCallBack, imageData, width, height, options);
   window.imageResizer.getImageSize(successCallBack, failCallBack, imageData, options);
   window.imageResizer.storeImage(successCallBack, failCallBack, imageData, options);

For Example:

window.imageResizer.resizeImage(
   function(data) { 
     var image = document.getElementById('myImage');
     image.src = "data:image/jpeg;base64," + data.imageData; 
   }, function (error) {
     console.log("Error : \r\n" + error);
   }, imageDataInBase64, 0.5, 0.5, {
      resizeType: ImageResizer.RESIZE_TYPE_FACTOR,
      imageDataType: ImageResizer.IMAGE_DATA_TYPE_BASE64,
      format: ImageResizer.FORMAT_JPG
   }
);

Android quirks and howto's

Android 2.3+ is supported

The storeImage funtion will always store the image to the device's default external storage, under the given Directory and filename. the photoAlbum property will be ignored.

iOS quirks and howto's

For a full iOS integration, two extra extensions should be used:

  1. Base64 Encoder/Decoder using Dave Wimer implementation (http://colloquy.info/project/browser/trunk/NSDataAdditions.h?rev=1576)
  2. Image Scaling for UIImage (Using the great howto guide here : http://iphonedevelopertips.com/graphics/how-to-scale-an-image-using-an-objective-c-category.html )

The sources are added to the github.

The storeImage function in iOS saves either in the photo album, or in the application's temporary directory. In the first case (photo album is set to true), the filename and directory will be completly ignored. A filename will be decided by iOS itself. In the second case, only filename will be used and directory will be ignored.

The MIT License

Copyright (c) 2012-2015 Raanan Weber ([email protected])

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.

phonegap-image-resizer's People

Contributors

allie-wake-up avatar csullivan102 avatar ddcovery avatar lovelyelfpop avatar raananw 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

phonegap-image-resizer's Issues

Error resizing on iOS

The plugin works well on Android but I wasn't able to make it work on iOS.

If I set in the options "photoAlbum: true" I see an alert "The image was placed in your photo album.", but I can't seem to find it (I looked in the "Photo/Camera Roll" app).

If I set it to false, or if I don't specify it, then the plugin return an error, but no message. I've tried with and without a "directory" property, ending and ending with "/".

What options are you using?

Sorry it was not an issue it was a doubt

window.imageResizer.storeImage(
function (data) {
var smallImage = document.getElementById('smallImage');
smallImage.src = dataURL;
},
function (error) {
console.log("Error : \r\n" + error);
},
file, {
imageDataType: ImageResizer.IMAGE_DATA_TYPE_URL,
filename: 'name',
directory: '/name',
format: 'jpg'
});

java.lang.IllegalArgumentException: URI is not hierarchical
my uri is base 64 string

Problem loading and writing files at file:///

The methods getImageUsingOptions and saveImage don't work with files that are located at file:/// I am working on iOS 7.0.4 and trying to use this plugin to save and access pictures. For some reason, the url is reconstructed to be file:///file:/[rest of the url string], which of course has nothing. The way that I have found around it is to remove the file:/// before attempting to configure the url strings or search for the files.

README.md is invalid for XCode 4.5

Your read me file states:

For iOS : add the following line to your config.xml after copying all classes to your classes folder:

But in XCode 4.5 there is no config.xml. we have plist files. Also should the classes go to the classes folder or the plugins folder? My facebook and Childbrowser plugins go in the plugins folder. Since this is a plugin I would have thought they would go there.

I really need to be able to use your plugin. And my deadline is short. Can you provide updated directions on implementing in IOS using XCode?

Instant crash on android :/

I get an instant crash of my app when trying to use this plugin.

Logcat:

E/AndroidRuntime(24259): FATAL EXCEPTION: pool-3-thread-2
E/AndroidRuntime(24259): Process: com.tech401.testApp, PID: 24259
E/AndroidRuntime(24259): java.lang.IllegalArgumentException: URI is not hierarchical: data:image/jpeg;base64,/9j/4AAQSkZJRg.....................
D/Error   (24259): ERR: exClass=java.lang.IllegalArgumentException
D/Error   (24259): ERR: exMsg=URI is not hierarchical: data:image/jpeg;base64,/9j/4AAQSkZJRgABAQA.....................
D/Error   (24259): ERR: file=File.java
D/Error   (24259): ERR: class=java.io.File
D/Error   (24259): ERR: method=checkURI line=222
D/Error   (24259): ERR: stack=java.lang.IllegalArgumentException: URI is not hierarchical: data:image/jpeg;base64,/9j/4AAQSkZJRgAB.....................
D/Error   (24259): ERR: TOTAL BYTES WRITTEN: 675824
W/ActivityManager(  756):   Force finishing activity 1 com.tech401.testApp/.MainActivity

How's she lookin?

Here's my code:

var canvasurl = canvas.toDataURL( "image/jpeg" )
window.imageResizer.resizeImage( function ( data ) {
    var imgg = "data:image/jpeg;base64," + data.imageData;
    console.log( 'imgg >', imgg )
}, function ( error ) {
    console.log( "Error : \r\n" + error );
}, canvasurl, 0.5, 0.5, {
    resizeType: ImageResizer.FORMAT_JPG,
    format: 'jpg'
} )

java.lang.IllegalArgumentException: URI is not absolute

Hi! My android app got crashed after attempt to resize an image.

imageResizer.resizeImage(ok,err, "file:///data/data/com.mtw.sarafan/files/resized", 40, 40, {pixelDensity: false, storeImage: true})

I get:

FATAL EXCEPTION: pool-1-thread-6
E/AndroidRuntime(12929): java.lang.IllegalArgumentException: URI is not absolute:
E/AndroidRuntime(12929):    at java.io.File.checkURI(File.java:220)
E/AndroidRuntime(12929):    at java.io.File.<init>(File.java:177)
E/AndroidRuntime(12929):    at com.synconset.ImageResizePlugin$ImageTools.storeImage(ImageResizePlugin.java:113)
E/AndroidRuntime(12929):    at com.synconset.ImageResizePlugin$ResizeImage.run(ImageResizePlugin.java:214)
E/AndroidRuntime(12929):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
E/AndroidRuntime(12929):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
E/AndroidRuntime(12929):    at java.lang.Thread.run(Thread.java:841)

Could you please help with this issue? Thanks in advance!

Cordova 2.1.0 conversion?

This seems like a great plugin, which I could desperately use for iOS and Android - but need to update for Cordova 2.1.0 use. I can help, but I'm not well versed in plugin development. Would you consider giving the conversion a shot?

getImageSize returns 0

I installed the plugin using CLI and called the function as
window.imageResizer.getImageSize(function(rep){console.log(rep)},function(rep){console.log("error");},uri,{imageType:"IMAGE_DATA_TYPE_URL"})
uri begins with file:/// (and tried without it)
Whatever I do, plugin returns 0 for height and width.

I am running it on IOS simulator and using phone gap 3.5.

Do you have any idea?

On Readme file there is a quirk mentions about Base64 Encoder/Decoder, is it related to that? It seems that, plugin already have these files. Should I run another code before it?

java.lang.IllegalArgumentException: URI is not hierarchical

Hi

I got this kind of msg when tried to convert image

Exception:
E/AndroidRuntime( 6003): java.lang.IllegalArgumentException: URI is not hierarchical: data:image/jpg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/4QNSRXhpZgAATU0AKgAAAAgA......

Code:
window.imageResizer.resizeImage(function() {alert('success')}, function() {alert('error')}, 'data:image/jpg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/4QNSRXhpZgAATU0AKgAAAAgABVEAAAQAAAABAAAAAFEBAAMAAAABAAEAAFECAAEAAAMAAAAASlEDAAEAAAABAAAAAFEEAAEAAAAB/AAAAAAAAAAAAAAAADMAAGYAAJkAAMwAAP8AKwAAKzMAK2YAK5kAK8wAK/8AVQAAVTMAVWYAVZkAVcwAVf8AgAAAgDMAgGYAgJkAgMwAgP8AqgAAqjMAqmYAqpkAqswAqv8A1QAA1TMA1WYA1ZkA1cwA1f8A/wAA/zMA/2YA/5kA/8wA//8zAAAzADMzAGYzAJkzAMwzAP8zKwAzKzMzK2YzK5kzK8wzK/8zVQAzVTMzVWYzVZkzVcwzVf8zgAAzgDMzgGYzgJkzgMwzgP8zqgAzqjMzqmYzqpkzqswzqv8z1QAz1TMz1WYz1Zkz1cwz1f8z/wAz/zMz/2Yz/5kz/8wz//9mAABmADNmAGZmAJlmAMxmAP9mKwBmKzNmK2ZmK5lmK8xmK/9mVQBmVTNmVWZmVZlmVcxmVf9mgABmgDNmgGZmgJlmgMxmgP9mqgBmqjNmqmZmqplmqsxmqv9m1QBm1TNm1WZm1Zlm1cxm1f9m/wBm/zNm/2Zm/5lm/8xm//+ZAACZADOZAGaZAJmZAMyZAP+ZKwCZKzOZK2aZK5mZK8yZK/+ZVQCZVTOZVWaZVZmZVcyZVf+ZgACZgDOZgGaZgJmZgMyZgP+ZqgCZqjOZqmaZqpmZ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ElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD+f+iiigD/2Q==', 0.5, 0.5, {resizeType:ImageResizer.RESIZE_TYPE_FACTOR ,format:'jpg'});

iOS crashes no matter what i change

hi

i use the following code in a phonegap app ... android works fine ... but iOS keeps crashing not matter what params i change

this is my code:

var filePath = window.rootFS.toURL() + window.mainDirectory + "/" + $scope.sCurrentDate + "/" + fileName;
var options = {
  format: ImageResizer.FORMAT_JPG,
  resizeType: ImageResizer.RESIZE_TYPE_PIXEL,
  directory: window.rootFS.toURL() + window.mainDirectory + "/" + $scope.sCurrentDate + "/",
  quality: 90,
  pixelDensity: false,
  storeImage: true,
  filename: fileName.substring(0, fileName.lastIndexOf('.')) + "_thumb.jpg",
  photoAlbum: true
};
window.imageResizer.resizeImage(function(image, height, width) {
  console.log(image);
}, function(data) {
  console.log(data);
  alert('failed' + JSON.stringify(data));
}, filePath, 500, 250, options);

Cordovoa 2.5.0 Uncaught reference

Hi there, am suffering from a weird error

04-02 23:41:40.625: E/Web Console(11574): Uncaught TypeError: Cannot call method 'resizeImage' of undefined:249

I have imageresize.js properly loaded after cordova-2.5.0.js.

Here is the code am using:

        var imgSrcPath = $('#preview_a_img').attr('src');
        if(parent.isMobile){  
            window.imageResizer.resizeImage(
              function(data) { 
                var image = document.getElementById('resized');
                image.src = "data:image/jpeg;base64," + data.imageData; 
              }, function (error) {
                console.log("Error : \r\n" + error);
              }, imgSrcPath, 0.5, 0.5, {resizeType:ImageResizer.RESIZE_TYPE_FACTOR ,format:'jpg'});

        }

Resizing an image with options.storeImage = true is not working

Hi,

When resizing an image with a file uri as a result (and not base64) the app CRASHES.
I have tried numerous options for the options.directory, and options.filename.. none worked. Eventually the result was the same - CRASH.

What am I doing wrong?
Is there a sample of a file uri as a result somewhere?

Thanks,
Doron

Image Resize function not working on Android

Hi,
I am calling "window.imageResizer.resizeImage()" with fileURL and storeImage = true. But it crashed android app, gives a popup message " Unfortunately app stopped working". I have used many options but unable to resize the image. Below are my recent options that I have tried.

        window.imageResizer.resizeImage(function(success_resp) {
            utils.debug('success, img re-size: ' + JSON.stringify(success_resp));
            callback(success_resp);
        }, function(fail_resp) {
            utils.debug('fail, img re-size: ' + JSON.stringify(fail_resp));
            // callback(fail_resp);
        }, img_path, $scope.order.category.width2, 0, {
            imageDataType : ImageResizer.IMAGE_DATA_TYPE_URL,
            resizeType : ImageResizer.RESIZE_TYPE_PIXEL,
            pixelDensity:true,
            storeImage : true,
            photoAlbum : false,
            filename : img_path.substr(img_path.lastIndexOf("/") + 1),
            format : 'jpg'
        });

Phonegap + IOS + image gets saved in tmp directory

Hi

this is the code i use in my phonegap app ... it saves the image in the tmp directory of the app i think so when i close the app and restart they are gone:

window.ImageResizer.resize(options,
  function(image) {
    console.log(image);
  }, function(data) {
    alert('failed');
  });

saving image with url not working

 window.imageResizer.storeImage(
              function(data) { 
                var smallImage = document.getElementById('smallImage');
                smallImage.style.display = 'block';
                smallImage.src = imageURI;

              }, function (error) {
                alert("Error : \r\n" + error);
                //console.log("Error : \r\n" + error);
              }, imageURI, {filename :"test",imageDataType:ImageResizer.IMAGE_DATA_TYPE_URL ,format:'jpg',directory:"/DCIM/Camera"});

this give a error NULL is there something wrong with the code?

ios saveImage(storeImage) directory issue

when the option "directory" is a file URL(start with "file://") on ios, the storeImage(saveImage) function failed.

add this line after "NSString *directory = [options objectForKey:@"directory"];" inside the "saveImage" function:

"directory = [self getUrl:directory];"

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.