1

Question - Is there any easy way (ex. CSS) to change the brightness and contrast of an image before sending it to ngx-image-cropper, so that when I call crop() the brightness/contrast persist to the final cropped output image?

Ex. load it into a viewer (ex. img tag), adjust brightness, then load it into the cropper window, adjust the zoom, cropped area, etc, then call crop() on the image to get the final output.

Problem - Nothing I'm trying seems to work to change the brightness of the final cropped image output and I'm aware the ngx-image-cropper library doesn't allow me to adjust brightness or contrast. I can only zoom and rotate. I'm also aware there are other libraries to do this, I'm stuck on finding one for Angular that is easy free and simple to use.

I have created and set up a Stackblitz demo here to show the process I use to get and crop an image.

Maybe I need to rethink the way I'm working with and editing an image, while using the cropper library?

Here is the code to demo the process

export class AppComponent  {
  @ViewChild(ImageCropperComponent) imageCropper: ImageCropperComponent;
  name = 'Angular';
  imageChangedEvent: any = '';
    croppedImage: any = '';
    
    fileChangeEvent(event: any): void {
        this.imageChangedEvent = event;
    }
    imageCropped(event: ImageCroppedEvent) {
        // this.croppedImage = event.base64;
    }
    load() {
        const croppedImageEvent = this.imageCropper.crop();
        this.croppedImage = croppedImageEvent.base64;
    }
    imageLoaded() {
        // show cropper
    }
    cropperReady() {
        // cropper ready
    }
    loadImageFailed() {
        // show message
    }
}
<input type="file" (change)="fileChangeEvent($event)" />

<image-cropper
    [imageChangedEvent]="imageChangedEvent"
    [maintainAspectRatio]="true"
    [aspectRatio]="3 / 2"
    [resizeToWidth]="300"
    format="png"
    (imageCropped)="imageCropped($event)"
    (imageLoaded)="imageLoaded()"
    (cropperReady)="cropperReady()"
    (loadImageFailed)="loadImageFailed()"
></image-cropper>
<div style="padding-bottom: 1rem">
    <input type="button" value="Load cropped image" (click)="load()" />
</div>

<img [src]="croppedImage" />
chuckd
  • 13,460
  • 29
  • 152
  • 331

1 Answers1

0

ngx-image-cropper only supports cropping related features. It doesn't come with other features such as brightness or contrast adjustment.

One of the popular paid library is pintura which supports Angular out of the box.

If you are only interested in open-source library, then this site has a good list: https://medevel.com/16-os-photo-image-editors/

skouch2022
  • 956
  • 1
  • 3
  • 13
  • ya it looks like pintura has a lot more features than I need and it's very expensive. I really only need 2 more features on top of what ngx-image-cropper gives me (brightness, contrast) and maybe a 3rd feature like sepia or something that I can use in conjunction with the others to enhance the image. – chuckd Mar 30 '22 at 04:49
  • Have you used CamanJS. It seems pretty good but it doesn't have any Angular port and I read that it's not supported anymore. – chuckd Mar 30 '22 at 04:49
  • @user1186050 CamanJS and DarkroomJS alike are no longer maintained for almost 10 years. You can try [Tui Image Editor](https://github.com/nhn/tui.image-editor#-documents). They seem to have Angular wrapper for it here: https://www.npmjs.com/package/tui-image-editor-angular – skouch2022 Mar 30 '22 at 05:01
  • this might sound like a stupid question, but will I have any issues using this in a Angular application if I use the Javascript version and not the Angular wrapper? – chuckd Mar 31 '22 at 02:43
  • @user1186050 No question is stupid question, and your question is a great one. I think you can use a JavaScript version with Angular, but the library needs to have the `xxxx.d.ts` or you need to see if the `xxx.d.ts` file is available somewhere to be download. This file is used by the compiler to understand and know what type to expect. – skouch2022 Mar 31 '22 at 03:19
  • I see a index.d.ts file that has lots of interfaces. Is that it or should there be more than 1? – chuckd Mar 31 '22 at 07:40
  • @user1186050 It might be it. You will need to play around with it. If you feel like helping the community, maybe you can try integrating the Lib into a new Angular app, then push it to GitHub. I might be able to collaborate with you, but I can't promise that. – skouch2022 Mar 31 '22 at 22:57
  • I would have no idea how to do that...right now I'm just looking for the quickest, and simplest way to crop, adjust brightness and contrast, zoom, and rotate an image so I can upload it to Cloudinary. The faster I can do this, the faster I can move on to more complicated issues in the app. I'm looking at just using a canvas tag and doing it with vanilla JS, or I'll try Toast UI photo editor with JS. – chuckd Apr 01 '22 at 03:42
  • Do you know what I'm doing wrong here? https://stackoverflow.com/q/71701917/1186050 – chuckd Apr 01 '22 at 04:51
  • @user1186050 I responded. – skouch2022 Apr 02 '22 at 04:36
  • What if you create your own? I mean you can add 2 range inputs values that bind to the CSS brightness and contrast values. Something like this: https://stackblitz.com/edit/angular-ngx-image-cropper-example-akgqg4?file=src/app/app.component.css – Kibé M.C Apr 06 '22 at 10:53