Git Product home page Git Product logo

Comments (4)

adonespitogo avatar adonespitogo commented on June 25, 2024

I think that is quite out of scope of this project. There are a lot of image processing libraries out there already. What we can do I think is to make the base64 data of an image compatible with those image processing libraries.

from angular-base64-upload.

adonespitogo avatar adonespitogo commented on June 25, 2024

https://github.com/sloops77/AngularImageProcessor

app.controller('mycontroller', function ($scope, imageProcessor) {
  $scope.onloadHandler = function (e, reader, file) {
    var options = {
      resizeMaxHeight: 150,
      resizeMaxWidth: 150,
      resizeQuality: 0.7
    };

    var url = URL.createObjectURL(file)

    imageProcessor.run(url, options, function(processedImage) {
      console.log(processedImage);
    });

  };
});

<input type="file" accept="image/*" ng-model="file" onload="onloadHandler">

from angular-base64-upload.

bnbon avatar bnbon commented on June 25, 2024

That would be totally awesone, thats exactly what I have been looking for!

from angular-base64-upload.

ohpyupi avatar ohpyupi commented on June 25, 2024

I tried to use imageProcessor using custom parser, but the documentation is very unfriendly and doesn't make sense at all. Can you update the document and post 'truly-working' example?

EDIT

Finally I got it work. But I still doubt if imageProcessor is still working or not. Thus, instead of imageProcessor, I decided to go Jimp.
Below is my custom parser that really works.

$scope.resizeImage = function (file, base64Object) {
  // file is a File instance that contains image data
  // base64Object is an object that contains compiled base64 out of 'file'
  var deferred = $q.defer();
  var url = URL.createObjectURL(file);
  Jimp(function (item) {
    item
    .resize(1280, Jimp.AUTO)
    .quality(50)
    .getBase64(file.type, function (err, newBase64) {
       if (err) {throw err;}
       base64Object.filetype = file.type;
       base64Object.base64 = newBase64;
       deferred.resolve(base64Object);
    });// end of getBase64()
  })
  .catch(function (err) {
     console.log(err);
   })
   return deferred.promise;
};

One thing we should note is that the base64 format in Jimp and 'angular-base64-upload' are slightly different. Jimp's base contains filetype info in base 64. Thus, it starts like this, "data:image/jpeg;base64, REALBASE64 COMES HERE". However, angular-base-64-upload's base64 doesn't contain 'data:image/jpeg;base64 ' part. If you take care of this part in back-end, it will smoothly works. Hope this will help anybody who's struggling with image processing custom parser.

from angular-base64-upload.

Related Issues (20)

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.