scottcheng / cropit

A "customizable crop and zoom" jQuery plugin.
http://scottcheng.github.io/cropit/
MIT License
874 stars 304 forks source link

Auto detect image type and SVGs? #142

Open phpMagpie opened 8 years ago

phpMagpie commented 8 years ago

I'm using cropit for all image upload files in our CMS to force users to upload images at exactly the right size and dimensions.

What would be the best way to check the file type being passed to cropit to allow it to export a JPG or PNG with transparency?

Also, can cropit handle SVG files?

phpMagpie commented 8 years ago

I've solved the detecting image type between .jpg/jpeg and .png by adding the following near end of getCroppedImageData() function within jquery.cropit.js itself:

if (exportOptions.type === 'image/jpeg') {
    canvasContext.fillStyle = exportOptions.fillBg;
    canvasContext.fillRect(0, 0, canvas.width, canvas.height);
}

However, I can't find any info about cropping SVG's. Anyone know if this is possible?

bharatpatil commented 8 years ago

You can make use of image onload callback.