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

Rectangle crop and results dimensions #21

Closed
crazy8brown opened this issue Nov 23, 2015 · 15 comments
Closed

Rectangle crop and results dimensions #21

crazy8brown opened this issue Nov 23, 2015 · 15 comments

Comments

@crazy8brown
Copy link

When using rectangle crop and I don't specify a result-image-size, the resulting rectangle is 200x200. If the crop area is truly a rectangle (w != h), this result includes whitespace.

My html:

<img-crop image="origImage" result-image="croppedImage" area-type="rectangle" chargement="'Loading'" result-image-quality="1.0" ></img-crop>

How can I force the component to use the crop rectangle dimensions instead? Shouldn't this be default mode for cropping a rectangle? Do I use the scaling property instead?

@crazy8brown
Copy link
Author

A little bit more. I'm able to work around this because I know the specific width and height I want the resulting rectangle to be, and I can enforce the rectangle aspect ratio. However, I would think that the default "size" for a rectangle should be the rectangle w/h relative to the original image size.

@CrackerakiUA
Copy link
Owner

As far as i remember, default is square. Correct me if i am wrong.

@crazy8brown
Copy link
Author

The default result-image-size is indeed a square (200x200). However, for a rectangular crop (area-type=rectangle) that isn't 200x200, you image will be padded or resized to fit into the 200x200 area. Let's say your rectangle is 200x100. The bottom half of your resulting image will be white.

I would think that by default, if the result-image-size attribute isn't specified for area-type= rectangle, you would automatically return an image that is relative to the original image. If the user specifies a result-image-size, the rectangular cropped area would be scaled appropriately. Let's say the original image is 2000x1000, and that scales to screen coordinates/image size of 200x100. I crop a rectangle that is 20x10 on the image. Without specifying the size, I'd expect that the resulting image would be 200x100 (Scaled relative to the original image size of 2000x1000). However, let's say I specified my result-image-size to w:250 h:125, then the cropped area would scale to fit those dimensions.

I think it's a strange behavior to conform a rectangle crop to 200x200 when you don't specify a result-image-size.

@laxu
Copy link

laxu commented Dec 10, 2015

I agree that it's non-obvious behavior, you should end up with a picture relative to the size of the rectangle drawn. Being able to have the result image size be based on the source image would not be a bad idea either. So for example if you upload a very large image then you can crop a portion of it and still have a large image in the output.

@CrackerakiUA
Copy link
Owner

hmmm, that can be easly fixed, if anyone need it i could give instructions on how.

@br8kpoint
Copy link

@CrackerakiUA I would appreciate these instructions as I am currently running into this issue. thanks

@CrackerakiUA
Copy link
Owner

in this line https://github.com/CrackerakiUA/ngImgCropFullExtended/blob/master/source/js/classes/crop-host.js#L279
you have check if result img is arr or simple, before those check add check if it's rectangle and it's not aspect ratio to change the result.

@andresarslanian
Copy link

andresarslanian commented Apr 27, 2016

Just to add to @CrackerakiUA last post, I did the following and worked for me (I DIDN'T test it with circles, I'm just using rectangles and works like a charm).

The original code was:

               else {
                    var aspectRatio = areaWidth / areaHeight;
                    var resultHeight, resultWidth;

                    if (aspectRatio > 1) {
                        resultWidth = ris.w;
                        resultHeight = resultWidth / aspectRatio;
                    } else {
                        resultHeight = ris.h;
                        resultWidth = resultHeight * aspectRatio;
                    }

                    temp_ctx.drawImage(image,
                        x,
                        y,
                        areaWidth,
                        areaHeight,
                        0,
                        0,
                        Math.round(resultWidth),
                        Math.round(resultHeight));
                }

                if (resImgQuality !== null) {
                    retObj.dataURI = temp_canvas.toDataURL(resImgFormat, resImgQuality);
                } else {
                    retObj.dataURI = temp_canvas.toDataURL(resImgFormat);
                }

And this is my modified code:


              else {
                    var aspectRatio = areaWidth / areaHeight;
                    var resultHeight, resultWidth;

                    if (aspectRatio > 1) {
                        resultWidth = ris.w;
                        resultHeight = resultWidth / aspectRatio;
                    } else {
                        resultHeight = ris.h;
                        resultWidth = resultHeight * aspectRatio;
                    }

                    // modified 
                    temp_canvas.width = resultWidth;
                    temp_canvas.height = resultHeight;

                    temp_ctx.drawImage(image,
                        x,
                        y,
                        areaWidth,
                        areaHeight,
                        0,
                        0,
                        Math.round(resultWidth),
                        Math.round(resultHeight));
                }

                if (resImgQuality !== null) {
                    retObj.dataURI = temp_canvas.toDataURL(resImgFormat, resImgQuality);
                } else {
                    retObj.dataURI = temp_canvas.toDataURL(resImgFormat);
                }

I hope it helps...

cheers!

@alex88
Copy link

alex88 commented May 10, 2016

@andresarslanian's version works perfectly, however it stil generates the image of 200 pixel in size

@alex88
Copy link

alex88 commented May 10, 2016

Nvm, if you use result-image-size="max" where max is a scope variable having max as string value it uses the full image resolution

@FaiyazMdAbdul
Copy link

@CrackerakiUA @alex88 setting result-image-size="max" causes the browser to freeze for images over 10mb and setting to "selection" renders very poor quality .

@CrackerakiUA
Copy link
Owner

CrackerakiUA commented Jun 4, 2016

image 10mb and langer you can resize to smaller inside cropper and send to server original image and crop it there with options from cropper. On all my project i have added resize down to 1920/1080 each max before opening the cropper and everything works smooth.

@ProdigyView
Copy link

This fix works for me too, the white space is gone. Why hasn't this been merged in yet?

@CrackerakiUA
Copy link
Owner

Need to give some time to add it as feature.

@rickerd
Copy link

rickerd commented Sep 12, 2017

This repo is dead.
Please move to the other project:
https://github.com/CrackerakiUA/ui-cropper

@rickerd rickerd closed this as completed Sep 12, 2017
jaroel added a commit to jaroel/ngImgCropFullExtended that referenced this issue May 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants