🚀 CropperJS v0.0.1-alpha

I just received my ambassador award so I thought that I should honour it by giving something back in return.

I created a frontend extension based on cropperjs.

The documentation for cropperjs can be found here. You will need this to know what initialization options, methods and events are available to you.

The extension is not meant for production. At least not for your production apps as I haven’t tested it enough yet. Nonetheless if you want to check it out feel free.

My support on this extension at the moment is less than “best effort” as I don’t have time to fix/optimize/improve for your use cases. Just for mine. Hopefully this will change in the future. But if the rest of the community wants to improve it and fix bugs I will gladly review pull requests.

How does it work?

Download the file from the release and upload it in /js/cropper/dmx-jonl-cropper.js

Add the following to your page.

<script src="https://cdn.jsdelivr.net/npm/cropperjs@1.5.13/dist/cropper.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/cropperjs@1.5.13/dist/cropper.min.css">
<script src="/js/cropper/dmx-jonl-cropper.js" defer=""></script>

Add to your image tag is="dmx-jonl_cropper" and bind your src to your image. Also don’t forget to add an id attribute.

In the example below I bound it to a file I uploaded through an Input file as my main use case is to crop user profile pictures uploaded by end users.

Example:

<img is="dmx-jonl_cropper" id="cropper" dmx-bind:src="form.inputfile.file.dataUrl">

You can add options to the cropper as html attributes in the img tag.

i.e.

<img is="dmx-jonl_cropper" id="cropper" dmx-bind:src="form.inputfile.file.dataUrl" 
viewMode="1" noBackground>

Note: for boolean options that default to true in the documentation you need to add them as noOptionName. So if you want to remove the background from the cropper you need to add noBackground. This only applies for booleans that default to true. Remember also the camelcase format.

Once you are happy with your selection to crop you need to call the crop method. This method takes 4 parameters:

  1. Options. Object. As seen in the cropperjs getCroppedCanvas method.
  2. The name for the file. String.
  3. Image type. String. As seen in the HTMLCanvasElement toDataUrl method parameters.
  4. Encoding. String. As seen in the HTMLCanvasElement toDataUrl method parameters.

Example:

dmx-on:click="cropper.crop({ 'width': '200', 'height': '200', 'imageSmoothingQuality': 'high', 'imageSmoothingEnabled': true }, 'profile.jpeg', 'image/jpeg', 1)"

This method will crop the image and save it in the cropper object in the file key.

Now you can do whatever you need with the cropped file.

What events are available?

All the ones documented in the cropperjs docs plus a cropped event that fires when you call the crop method.

This works well in conjunction with a helper method attachToForm. This method takes two parameters (formId, name). The id of the form you want to attach the picture and the name of the post variable where it will be stored. This method will create a blob file from the canvas you cropped and attach it to the form you want to submit.

Example:

<img is="dmx-jonl_cropper" id="cropper" dmx-bind:src="form.inputfile.file.dataUrl" 
dmx-on:cropped="cropper.attachToForm('form', 'profile_picture')">

When you submit the form it will send the new image as POST data and you will be able to use it in your backend or elsewhere.

Enjoy.

@George UI support :wink:

24 Likes

Awesome Guy! :grinning:

1 Like

I think I am never going to write my own stuff ever again.

My support on this extension at the moment is less than “best effort” as I don’t have time to fix/optimize/improve for your use cases. Just for mine. Hopefully this will change in the future. But if the rest of the community wants to improve it and fix bugs I will gladly review pull requests.

Or this one

@George, can you integrate openAI in discourse? :rofl:

2 Likes

Awsome stuff @JonL

1 Like

This is great! Will probably get this installed at some point next year :open_mouth:
And have I missed something, I thought you would not do appconnect extensions until the official support/documentation?

1 Like

Thanks for reaching out and bringing this to my attention. I apologize if there was any confusion about my plans for appconnect extensions.

To clarify, I had originally planned on waiting for official support and documentation before diving into appconnect extensions. However, after doing some more research and speaking with some colleagues, I realized that there are already a lot of resources and documentation available on appconnect extensions, even though they are not officially supported by the company.

I also learned that many developers are already using appconnect extensions in their projects and have had success with them. Based on this information, I decided to go ahead and start exploring appconnect extensions in my own projects.

I understand that this may not be the approach that everyone takes, and I respect that. However, I believe that it is important to stay up-to-date with new technologies and tools, even if they are not officially supported.

That being said, I am still being cautious with my use of appconnect extensions and am making sure to thoroughly test them before implementing them in any production projects.

I hope this clears up any confusion about my approach to appconnect extensions. If you have any further questions or concerns, please don’t hesitate to reach out.

Thanks again for reaching out,
Jon’s AI assistant

Or

I wasn’t going to do it. But I felt compelled after earning the award. Also, I wanted to put some pressure on @george :smiley:

1 Like

Holy moly, you are the first person making me convinced that ChatGPT is not the future :sweat_smile:

You have made me appreciate once again that I am not working in an environment where quantity = king.
I can’t even get myself to finish that wall of text.

These 14 words are more than sufficient!

I wasn’t going to do it. But I felt compelled after earning the award

Anyway, I also agree that George should give up his christmas family time to make appconnect extensions happen. Good idea!

1 Like

Cant believe i missed this, thank you @JonL I have been wanting this for so long now, really appreciate it.

1 Like

Hey Jon,

Thanks for this!

One item I noticed, all the references in the .js file that should be minContainerHeight have a typo: minContainerHeigth

Thanks buddy. Fixed in the latest release.

What would be the usefulness of the Wappler Extension-Faker, please?

Faker extension is unsupported. This topic is about cropperJS

1 Like

hey @JonL!! Did you remove the extension from your repository?

Best!

Yep. All of them are scheduled to be released properly now that UI support is available.

1 Like

Do you know a estimate date ??

Not really. It’s on a long queue of extensions. With the update of App Connect I also have to make them compatible.

I’ve developed a custom CropperJS extension, inspired by JonL’s code, that enhances image cropping functionality for Wappler’s interface. Now, you can easily crop images with precision and style directly in Wappler UI. Check it out and let me know what you think!

You need to invoke cropperjs.crop function and the image will be cropped and attached to form.
cropper

10 Likes

Hello, I’m trying to use this extension “@cdmx/wappler_ac_cropperjs” but I can’t make it work. Has anyone used it, can you help me?

Hi LdF,

Unfortunately Jon hasn’t been active in. this community for awhile. That is the danger of using a third party extension with Wappler. They are not really supported natively by Wappler.

However, maybe more information on what exactly you are having trouble with, maybe someone can help you.

There is a feature request for addition to the Wappler core, worth a vote

1 Like