Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing the problem of different height and size for cropped image #161

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions source/js/classes/crop-host.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ crop.factory('cropHost', ['$document', 'cropAreaCircle', 'cropAreaSquare', 'crop
// Result Image size
var resImgSize=200;

var resImgHeight = 200;
var resImgWidth = 200;

// Result Image type
var resImgFormat='image/png';

Expand Down Expand Up @@ -168,10 +171,17 @@ crop.factory('cropHost', ['$document', 'cropAreaCircle', 'cropAreaSquare', 'crop
var temp_ctx, temp_canvas;
temp_canvas = angular.element('<canvas></canvas>')[0];
temp_ctx = temp_canvas.getContext('2d');
temp_canvas.width = resImgSize;
temp_canvas.height = resImgSize;

// temp_canvas.width = resImgSize;
// temp_canvas.height = resImgSize;

temp_canvas.width = resImgWidth;
temp_canvas.height = resImgHeight;


if(image!==null){
temp_ctx.drawImage(image, (theArea.getX()-theArea.getSize()/2)*(image.width/ctx.canvas.width), (theArea.getY()-theArea.getSize()/2)*(image.height/ctx.canvas.height), theArea.getSize()*(image.width/ctx.canvas.width), theArea.getSize()*(image.height/ctx.canvas.height), 0, 0, resImgSize, resImgSize);
// temp_ctx.drawImage(image, (theArea.getX()-theArea.getSize()/2)*(image.width/ctx.canvas.width), (theArea.getY()-theArea.getSize()/2)*(image.height/ctx.canvas.height), theArea.getSize()*(image.width/ctx.canvas.width), theArea.getSize()*(image.height/ctx.canvas.height), 0, 0, resImgSize, resImgSize);
temp_ctx.drawImage(image, (theArea.getX()-theArea.getSize()/2)*(image.width/ctx.canvas.width), (theArea.getY()-theArea.getSize()/2)*(image.height/ctx.canvas.height), theArea.getSize()*(image.width/ctx.canvas.width), theArea.getSize()*(image.height/ctx.canvas.height), 0, 0, resImgWidth, resImgHeight);
}
if (resImgQuality!==null ){
return temp_canvas.toDataURL(resImgFormat, resImgQuality);
Expand Down Expand Up @@ -291,9 +301,24 @@ crop.factory('cropHost', ['$document', 'cropAreaCircle', 'cropAreaSquare', 'crop
};

this.setResultImageSize=function(size) {
size=parseInt(size,10);
if(!isNaN(size)) {
resImgSize=size;

if(typeof size == 'number'){
size=parseInt(size,10);
if(!isNaN(size)) {
// resImgSize=size;
resImgHeight=size;
resImgWidth=size;
}
}
else if(typeof size == 'object' && size.height && size.width){
var height=parseInt(size.height,10);
var width=parseInt(size.width,10);
if(!isNaN(height)) {
resImgSize=height;
}
if(!isNaN(width)) {
resImgSize=width;
}
}
};

Expand Down