cstefanache / angular2-img-cropper

Angular 2 Image Cropper
MIT License
364 stars 135 forks source link

Set image without "chose file" button #19

Closed gfranco93 closed 8 years ago

gfranco93 commented 8 years ago

Addressing closed issue 18 from user @Mihai-B :

You just need to set the image from your app.component: this.data = {"image":YourImage};

Mihai-B commented 8 years ago

This is just when you initialize the cropper. Using my method, you can set a new image whenever needed without re-instantiating the cropper. I would say this fix is not really needed.

gfranco93 commented 8 years ago

You're right when you say that it's just for initializing the cropper, I made it that way because of the plunker (this.data = {};).

Using you idea you will have to add 'cropper' to the outputs of ImageCropperComponent (to avoid creating the ImageCropper outside of ImageCropperComponent), am I right?

I think both ideas can coexist, could you upload a PR?

Mihai-B commented 8 years ago

Yes both of them can coexist. I don't need to upload a PR because you can already implement my solution also.

Here is a quick example:

<div class="row">
  <img-cropper [image]="data" [settings]="cropperSettings" [cropper]="cropper"></img-cropper>
  <br>
  <img [src]="data.image" >
</div>

and: public cropper: ImageCropper; and in constructor:

 this.cropper = new ImageCropper(0, 0, this.cropperSettings.width, this.cropperSettings.height,
      this.cropperSettings.croppedWidth, this.cropperSettings.croppedHeight, this.cropperSettings.keepAspect);

And in a method where you want to add the new image for cropp:

let imgObj = new Image();
imgObj.src = 'data:image/png;base64,' + templateFile.fileData;
this.cropper.setImage(imgObj);
gfranco93 commented 8 years ago

Great!

cstefanache commented 8 years ago

Is this still an issue?

gfranco93 commented 8 years ago

No, closing.