Mawi137 / ngx-image-cropper

An image cropper for Angular
MIT License
780 stars 208 forks source link

The cropper image shrinks when moves the cropper #320

Closed bogdanbaghiu closed 4 years ago

bogdanbaghiu commented 4 years ago

Hello.

When I load the image, a small thumbnail image of the loaded image appears. I would like it to look bigger. The mistake is that when I move the trimmer, without touching either side, the original image of the thumbnail gets smaller. I would also like the preview to always be the same size as 300px high or to be able to load a 1080px image and automatically resize it to 500px height.

Attached code.

@Component({ selector: 'app-ci-image-viewer', templateUrl: './ci-image-viewer.component.html', styleUrls: ['./ci-image-viewer.component.scss'] }) export class CiImageViewerComponent implements OnInit { imageChangedEvent: any = ''; croppedImage: any = 'https://www.humanrightslogo.net/sites/all/themes/humanrights/images/human_rights_logo.jpg';

constructor() { }

ngOnInit() { }

fileChangeEvent(event: any): void { this.imageChangedEvent = event; } imageCropped(event: ImageCroppedEvent) { console.log(event); this.croppedImage = event.base64; } imageLoaded() { // show cropper } cropperReady() { // cropper ready } loadImageFailed() { // show message }

}

- ci-image-cropped.html

Preview


- ci-image-cropper.scss

.flex-container { display: flex; flex-direction: row; }

.cropper { background: transparent; }



When import this image, console show me the width and height for image:

![image](https://user-images.githubusercontent.com/37840937/80085732-f0b17780-8558-11ea-945a-664c47b80dd3.png)

And now move the cropper, without resize them, and in the console show me the new image resize and smaller image resized. Why? I don't know.

![image](https://user-images.githubusercontent.com/37840937/80086055-733a3700-8559-11ea-91a2-48b8c1c5bca2.png)

Thanks. 
Mawi137 commented 4 years ago

To resize the image you can use the resizeToHeight input or for better quality of the image, use another lib to do so.

The second issue might be due to the flexbox. It seems that once the image is cropped the first time, the preview is shown and it pushes the image cropper to the left, making it smaller.

bogdanbaghiu commented 4 years ago

Thanks @Mawi137. But my question is possible to resize image (the smallest) in the cropper size? And other question, the cropper is possible to incremented height with picked the horizontally-middle point?

image

Mawi137 commented 4 years ago

I don't understand your first question.

There's a readme with all the options. You can run off the forced aspect ratio, you can choose your own aspect ratio if you want and so on.

bogdanbaghiu commented 4 years ago

The first questions refers to smallest image (cropped image) to contrains within in cropped aspect ratio, but i solved. And the sechond thanks. I close the issue. Regards.