Giter VIP home page Giter VIP logo

nova-image-cropper's Introduction

Image Field with built-in cropper for Laravel Nova

This field extends Image Field adding a handy cropper to manipulate images. Can be configurable in the same way as a File field in Nova.

Demo

Demo

Install

Run this command into your nova project: composer require r64/nova-image-cropper

Add it to your Nova Resource:

use R64\NovaImageCropper\ImageCropper;

ImageCropper::make('Photo'),

Update form

In order to edit the existing image saved in the model, ImageCroper uses the preview method to return a base64 encoded image. You can either use the default implementation or override it as long as you return a base64 image.

use R64\NovaImageCropper\ImageCropper;

ImageCropper::make('Photo')
        ->preview(function () {
            if (!$this->value) return null;

            $url = Storage::disk($this->disk)->url($this->value);
            $filetype = pathinfo($url)['extension'];
            return 'data:image/' . $filetype . ';base64,' . base64_encode(file_get_contents($url));
        });

Options

Avatar mode

You can add a rounded mask to the preview and the cropper

ImageCropper::make('Photo')->avatar()

Custom aspect ratio

Define the fixed aspect ratio of the crop box.

  • Type: Number
  • Default: NaN
ImageCropper::make('Photo')->aspectRatio(16/9)

For free ratio use:

ImageCropper::make('Photo')->aspectRatio(0)

Localization

Set your translations in the corresponding xx.json file located in /resources/lang/vendor/nova

...

  "Edit Image": "Editar Imagen",
  "Cancel Crop": "Cancelar Recorte",
  "Change Image": "Cambiar Imagen",
  "Done": "Hecho",
  "Click here or drop the file to upload": "Click aquรญ o arrastra el archivo para comenzar la subida"

nova-image-cropper's People

Contributors

beliolfa avatar cretueusebiu avatar dependabot[bot] avatar icaroce avatar riesjart avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

nova-image-cropper's Issues

Support for Custom Aspect Radio

Hi there ๐Ÿ‘‹,

would be great if I could set the aspect ratio per image.
If you could point me to the right files to edit, I would do it myself and push a pull request ๐Ÿ˜Š.

I assume I would have to add a new method in ImageCropper and pass the value to the aspect-ratio property?

Circle cropping

Is there anyway to customize the cropper and use Circular cropper placeholder? so we can see if the image will displayed probably in circle in the app?

Details maxWidth not works in details page

Hello.

How can i change the detail image size? I need to reduce the image dimensions, but both with or without ->avatar() method, when uses Image ->maxWidth(XX) not works because the size is fixed at your css... 318x318 px

Don't removes old image when upload a new one

When edit & save a new resource, and upload/crops an image, the new uploaded image is stored fine. But the old image is not removed on store.

If user change the image, i don't understand the need to mantain the old image; so i thing the old image must be removed.

Nova 4 support?

Hi there,

Thanks for providing this :)

I just tried installing this in a new app which is using Nova 4, and the cropper does not show up, there are some javascript errors in the console, so my assumption is that it does not work with Nova 4.

Screenshot 2022-11-28 at 08 01 44

I am willing to pay for your time helping me upgrade this :)

storeOriginalName() always store 'uploaded_file.jpg' as filename

Here is my code (same as sample in the readme.md):

ImageCropper::make('Photo')
->disk('public')
->prunable()
->storeOriginalName('photo_name')
->storeSize('photo_size')
->preview(function () {
if (!$this->value) {
return null;
}
$url = Storage::disk($this->disk)->url($this->value);
$filetype = pathinfo($url)['extension'];
return 'data:image/' . $filetype . ';base64,' . base64_encode(file_get_contents($url));
})
->aspectRatio(16/9),

Although I have use the storeOriginalName(), it keep store 'uploaded_file.jpg' as filename. How to store the original filename?

And another issue is with the same configuration, when edit the resource (Edit Form), it didn't display the stored image. It only able to display stored image in details screen. Is it a correct behaviour?

Aspect ratio should be "forced"

If I define an aspect ratio, editor should open automatically "edit image" after upload in order to force user to crop the image.

If users ignore this step, they could upload not cropped image.

Maximum execution time of 30 seconds exceeded

I'm getting this error randomly on index, details and edit page for records with an image. I guess it's related to the image preview, because when there is no image on any records, everything works as expected, but right after adding an image to first record, this error happens.

My resource is as simple as:

            ImageCropper::make('Image')
                ->prunable()
                ->rules('nullable', 'image', 'max:5120')
                ->aspectRatio(10 / 8)

Image always stored in PNG format

Version: 1.1.4

Image always stored in PNG format. How to store image follow original type?

And how to store original filename in the storage path? Currently if using storeOriginalName() method, it only save the original name in that particular database column, not as the actual file name in the storage path.

Not showing image when edit a resource item

Hi, i crop and upload the image fine and it's shown right in index and details page. But when edit a row, the image is not shown. See my code:

ImageCropper::make('Avatar', 'avatar')
    ->disk('my_custom_disk')
    ->path('images/usuarios/'.str_pad($this->id, 10, "0", STR_PAD_LEFT))
    ->preview(function () {
        if (!$this->value) return null;

        $url = Storage::disk($this->disk)->url($this->value);
        $filetype = pathinfo($url)['extension'];
        return 'data:image/' . $filetype . ';base64,' . base64_encode(file_get_contents($url));
    })->avatar(),

I think it's a good idea to preview the image when editing too... but only update it when user re-crops the image, upload & crop a new image.

Uploaded file real name not working

Hi, first of all, thanks for the great plugin, it's helping me a lot.

A problem I'm facing is that I need to save the original file name and it size.
The problem is that the plugin manually set uploaded_file.jpg to original Name.
I can confirm that this happens just with this plugin. The native ImageField works great.

In file PicturePicker.vue I found:

// The default value been set
69: originalName: 'uploaded_file.jpg',

...

// The originalName is been replaced, but for some reason it's not working.
119: this.originalName = file.name

Strange issue with website with basic auth

Hi, I cannot get image preview on my production environment (where a basic auth is available).

Looking into your code I found this snippet

        $url = Storage::disk($this->disk)->url($this->value);

        $path_info = pathinfo($url);

        $filetype = 'jpg';

        if (array_key_exists('extension', $path_info)) {
            $filetype = $path_info['extension'];
        }

        try {
            $encoded_file = base64_encode(file_get_contents($url));
        } catch (\Exception $e) {
            return '';
        }

This force PHP to perform a http request because ->url method, on Storage, return an absolute url (that breaks down on my environment).

I don't know if it's the right behaviour....

Buttons wrap on smaller screens

Y'all, I am so happy for this package. Thank you!

Quick note: The button text wraps on smaller screens, and it'd be awesome if it didn't. <3

image

Problem using `php artisan serve`

Using laravel internal http server, this packages doesn't work.
It crashes the web server.

Using Apache or Nginx it works... very strange

Avatar support

Thanks for the library

Did you plan to support avatar?

Avatar is not displayed in search results next to title

Currently, avatar is not being shown next to title as stated here. See the below image. I don't know if I am doing something wrong.

Screen Shot 2020-10-21 at 21 38 24

I was able to fix this by implementing Laravel\Nova\Contracts\Cover interface in ImageCropper class. The original Laravel\Nova\Fields\Avatar field also implements that.

Is there any other way to achieve this currently?

Forced crop without aspect ratio

ImageCropper is forcing a crop immediately after selecting a file. It also forces an aspect ratio even if this function has not been called.

Does not work when using ->showCreateRelationButton();

Lets say that the post belongs to a user: BelongsTo::make('User')->showCreateRelationButton();

If that User resource is using this package (The image cropper) when you go to the Post resource and click the + button (To create a new User for the post) it doesn't show anything and flickers.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.