There has been an error cropping your image

Support » Fixing WordPress » There has been an error cropping your image There has been an error cropping your image Resolved anthonykung (@anthonykung) 5 years ago Hello, There’s…

Viewing 15 replies — 1 through 15 (of 22 total)

  • I had already looked through every thread regarding this and that does not help since my PHP version is already at 7.0 as stated above. Clearing caches do not work too.

    • This reply was modified 5 years ago by anthonykung.

    Ah never mind, fixed it. Its the GD Library not installed.

    Here’s the SSH line command to install it:
    sudo apt-get install php7.0-gd
    Use this to stop Apache for it to make changes.
    sudo apachectl stop
    Start Apache now and everything is fixed.
    sudo apachectl start

    Hmm, now that I thought of it, this forum isn’t really helpful as promised.

    now that I thought of it, this forum isn’t really helpful as promised.

    This is a WordPress support forum, run by volunteers.

    And for that, it’s awesome.

    In fact, many people are humbled by the kind of support they receive here for free when their theme/plugin vendors and hosts they’re paying month after month are unable or just refuse to help them.

    It’s not a server administration forum.

    Was your “fix” in anyway related to WordPress at all?

    It runs on WordPress why else will I ask here, there’s no requirement for this only PHP versions and MySQL. If it’s regarding SSL installation fine it’s not WordPress, but this is WordPress’s Media Library and there’s no manual saying that I should install that. I figure it out myself after studying WordPress functions.php and that suppose to be what a proper “volunteer” should help instead of sending a random link to a thread without considering the WordPress forum rule is to look for similar issues before posting.

    As a WordPress user, I appreciate your help @anthonykung

    @anthonykung or anyone else, could you perhaps help me to understand how to put those commands in? I am having the same problem but I am not a programmer.

    Sure thing @clarecorker,

    First you need to log into your server using SSH. Simply open Command Prompt (cmd) for Windows or Terminal for Mac and type the following:

    SSH [username]@[server-ip]
    Replace the []
    Then it will ask for password just type it in, for security reasons you won’t see what you’re typing.

    After that you should be logged in and you’ll just have to install the GD library by typing:

    sudo apt-get install php7.0-gd

    Final step is to restart your server, if you’re using Apache2 use apachectl restart if you’re using Nginx try service nginx restart

    Hope this helps.

    Just wanted to say thanks for this. I completely overlooked the missed dependency. You saved me a ton of time.

    @anthonykung, I had this same issue. My question is this: how did you discover which module was missing? I’m running on FreeBSD and apparently lots of PHP modules that are installed by default on Linux are missing here. I’ve had to install quite a few, gd being just the latest. In all other cases, I found errors in the Apache error log for the web page which indicated a missing function. I’d then Google around to find out which PHP module that function is in, add it, restart Apache, and poof, fixed. In this case, however, there was no error listed so I was lost until I found your post. So… how’d you figure it out?

    @anthonykung
    I’m glad your post has helped others. I do think though that you could have demonstrated a little more courtesy to @gappiah. Like he said, volunteers run this board. Putting @gappiah on the defensive for the community, in my opinion, didn’t help anyone. Also, nowhere do I see a ‘promise’ that anyone will help you here.

    Some might argue that given the level of knowledge you appear to have in your original post, it seems like you must have just overlooked the fact that you would need an image library to manipulate images on the server. Sometimes even just writing down your issue, or talking to another developer can lead you to a solution. Not everyone resolves problems in the same way. This is the human condition, and communication is the catalyst for higher learning. I don’t know maybe you were just in a bad mood, frustrated by the issue you were faced with. I think if you read your post again, you might see my point. If not, that’s ok too.

    At any rate, for those that might stumble upon this thread seeking answers to their own problems. Take a look here if you are having some similar issue like something not working and no error seems to be generated.

    https://wordpress.stackexchange.com/questions/42098/what-are-php-extensions-and-libraries-wp-needs-and-or-uses

    Remember, not everyone is a front-end developer, a back-end developer, a middleware developer, a designer, a Linux expert, a command line cowboy, a server administrator, a DevOps expert, a cms administrator, a website troubleshooting expert, or a volunteer forum contributor.

    But everyone is a person and deserves respect for any assistance they offer to anyone who asks. My hats off to all volunteers and member of this forum. Without you, there would be no support.

    @anthonykung Thank you, your post helped me finally after I wasted around 8 hours fighting with this unknown dependency.

    The problem with this kind of issues is that, wordpress hides the OS error messages and just tells you “there has been problem”. That is a damn dead-end! If there is no proper documentation at codex, I have to google it, search through and filter all the responses for an answer or just read the core code all by yourself and figure it out. If I have so much time, why would I even choose wordpress unless I am making use of some powerful features which are most essential for my site ? For example, for next static site, I would probably go with some Html5 template if I need to do a quick job.
    I can understand the frustration and it is in no way to put down the wonderful help of volunteers do.

    @thorak01 Thank you for your link to stackexchange question, I also found that I need php-ssh2 library. There are many out-dated answers there, so here is a quick summary of what I did. I use wp-cli i.e. wp command line utility on ubuntu.

    $  wp install git@github.com:johnbillion/ext.git
    $  wp ext check 
    # This prints all the recommended php extensions.
    
    +-----------+-----------+
    | extension | installed |
    +-----------+-----------+
    | mbstring  |           |
    | ssh2      |           |
    | curl      | 1         |
    | date      | 1         |
    | dom       | 1         |
    | exif      | 1         |
    | filter    | 1         |
    | ftp       | 1         |
    | gd        | 1         |
    | hash      | 1         |
    | iconv     | 1         |
    | imagick   | 1         |
    | json      | 1         |
    | libxml    | 1         |
    | mysqli    | 1         |
    | openssl   | 1         |
    | pcre      | 1         |
    | posix     | 1         |
    | SimpleXML | 1         |
    | sockets   | 1         |
    | SPL       | 1         |
    | tokenizer | 1         |
    | xml       | 1         |
    | xmlreader | 1         |
    | zlib      | 1         |
    +-----------+-----------+
    
    sudo apt install php-ssh2
    sudo apt install php-mbstring
    sudo systemctl restart apache2

    Hope this helps few others too.

    I have resolved this issue with WordPress 5.0 ,PHP 7.2 Nginx

    sudo apt-get install php7.2-gd

    sudo systemctl restart nginx

    Now you can check my site its working fine https://www.nanhekumar.com/

    Hey thanks… that was a really useful tip. and thanks for resolving your own question!

    joe

    (@joevistatech)

    I installed the GD library just fine, and did a graceful restart of apache. Unfortunately, no dice for me. There are a slew of other things I would try, but I’m still treading lightly on best practices here at my work.. the site(s) I need to update the favicon for are sitting on RedHat Linux VMs in Azure. Due to the setup, I cannot just sftp put the favicon.ico where I need it.

    Workaround (for anyone else still having the issue, beyond following suggestions above):
    Install/activate “Very Simple Favicon Manager” by Guido. It has not been updated in a while, but I gave it a shot and it worked like a charm.

  • Viewing 15 replies — 1 through 15 (of 22 total)

    I am setting the header image in WordPress and when I click on the crop button, it shows me the following error:

    There has been an error cropping your image.

    enter image description here

    cjbj's user avatar

    cjbj

    14k16 gold badges41 silver badges84 bronze badges

    asked Apr 30, 2018 at 10:59

    Dead Pool's user avatar

    There is too little information to be completely sure, but usually this error occurs when WordPress cannot find the graphic library which should be installed on your server. So you should check with your provider to see if Imagick and/or GD are installed.

    You can also add this little snippet of code in your functions.php file to make sure WordPress looks for both (often it only looks for Imagick):

    add_filter ('wp_image_editors', 'wpse303391_change_graphic_editor');
    function wpse303391_change_graphic_editor ($array) {
        return array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' );
        }
    

    This snippet will look for GD first and then for Imagick. The latter gives better quality, but uses more memory, which can also lead to server errors.

    answered Apr 30, 2018 at 11:37

    cjbj's user avatar

    cjbjcjbj

    14k16 gold badges41 silver badges84 bronze badges

    2

    I solved this installing the next library

    sudo apt-get install php5-gd -> for php5

    sudo apt-get install php7.0-gd -> for php7

    sudo apt-get install php7.2-gd -> for php7.2

    answered Oct 22, 2018 at 15:01

    Fabrizzio's user avatar

    2

    I was facing same issue and unable to understand how to resolve this issue by following given ideas on every portals as I am not hardcore programmer so it was not possible for me to understand their tricks but Now I have successfully troubleshooted this image cropping issue and am sharing my trick how it was troubleshooted.

    You just have to open your xampp controller and stop both the services Apache and MySQL and now click on congfig button of Apache and select PHP(PHP.ini), After selecting you will see a config file, find

    ;extension=gd
    

    text, Now just remove ; to enable gd services at your system for PHP as by default it comes with commented and save the file and restart both services Apache and MySQL.

    I hope this will help you.

    Rup's user avatar

    Rup

    3,7134 gold badges24 silver badges27 bronze badges

    answered May 26, 2021 at 20:34

    Nitin Tomar's user avatar

    1

    I had encountered the same issue with my blog, after searching for a while found out that it was because GD library for PHP which was not installed on the server

    Since my server is hosted on CentOS, to find the GD Library package within CentOS repository

    $ sudo yum list available | grep 'gd'
    

    Identify GD Library package name and install it

    $ sudo yum install php-gd
    

    Restart apache service

    $ sudo service httpd restart
    

    A detailed article that I wrote can be found here with command output screenshots

    cigien's user avatar

    answered Aug 24, 2019 at 13:31

    RohuTech's user avatar

    1

    Can you imagine your WordPress site without images? Images bring out the personality of any content.

    Sometimes when you edit an image before uploading, you will see the message

    There has been an error cropping your image.

    ‘WordPress error cropping image’ mainly happens because of the absence of the GD (Graphics Draw) package.

    Today lets see what leads to this error and how our Support Engineers fix this for our customers.

    How does image cropping error look?

    WordPress offer freedom to build websites, hobby blogs, etc. Hence it always includes features to upload images.

    Let’s take a look at how the image cropping error look.

    To upload an image in WordPress users use the option “Select and Crop”. Then adjust the crop selection, then select “Crop Image”. When things do not work, it shows the message ‘There has been an error cropping your image’. Here, the WordPress “Media Library” turns grey and results in the error.

    Image displaying error in text formate 'There has been an error cropping your image'.

    The most common reason leading to the error is missing the PHP-GD library.

    Mostly, when we hear about PHP in WordPress, the first thing that we use to relate is HTML. But PHP is also used to create and edit image files. Image formats supported include GIF, PNG, JPEG, WBMP, and XMP.  In general, PHP allows uploading an image directly into the browser. And, it’s the GD library that makes image functions work.

    How we fix WordPress image cropping error

    We now know how the error looks. Moving on further let’s check on how our Support Engineers fix image cropping error for our customers.

    As the first step of troubleshooting, we check the server’s PHP version along with the GD package.  If the GD package is missing, we install it. However, the GD installation steps differ depending on the server type.

    For RedHat/ CentOS hosts, we run the command

     yum install php-gd

    Or, if it is an Ubuntu server, GD installation works using

     apt-get install php-gd

    Here, our Support Team also makes sure that the version of the WordPress package matches the PHP version of the host.

    Finally, to make the newly installed GD package, the webserver needs a restart. We do this in the server by

    /etc/init.d/httpd restart

    After fixing the error, in the “Media Library,” the user can select the image and “Insert into post”.

    Media library after fixing the error

    [Need help in fixing WordPress error? We are here 24×7.]

    Conclusion

    In short, the main reason for the WordPress error cropping image will be missing the GD package on the server. Today, we saw how our Support Engineers check and fix image uploading error for our customers.

    PREVENT YOUR SERVER FROM CRASHING!

    Never again lose customers to poor server speed! Let us help you.

    Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

    GET STARTED

    var google_conversion_label = «owonCMyG5nEQ0aD71QM»;

    • Posts

    • I am unable to crop a new header image today. I have been doing this blog for quite a few years, and this never happened before. I try to crop a new image for the header, and I get an error message. I tried this several times today and the same thing happened. Can this be fixed?

      Site: https://roughinhere.wordpress.com.
      WP.com: Yes
      Correct account: Yes

      @Soberbanda31, thank you for responding to this.

      The only error message that I get is:

      “There has been an error cropping your image.”

      I am not getting any other information.

      I have been cropping images for headers in my WordPress blog for quite a few years. I have been doing this blog for over 14 years. I’m not doing anything different from what I was doing before, and the process is very simple, too. It always worked; I never had a problem cropping a picture for the header image. But it’s not working now.

      Hi there,

      Sorry to hear that you’re having issues. We aren’t aware of any widespread issues with cropping header images. Could you try clearing the browser cache to rule out this being any browser-specific issues? Here’s how to clear your browser cache: https://en.support.wordpress.com/browser-issues/#clearing-your-browser-cache

      If that doesn’t help, please try using a different browser altogether to see if that helps. If that doesn’t work either, please take a screenshot when the error message appears and upload it to your media library here: https://wordpress.com/media

      We’ll look into it further once you’ve uploaded the screenshot after following the steps mentioned above.

      Regards

      @chardsinger You can try one or several of these below mentioned steps to help resolve that issue:

      1. Clear your browser and site cache.
      2 .Deactivate all plugins temporarily to check if the problem still persists.
      3. Switching back to default theme temporarily.
      4. Remove inactive plugins.

      Let me know if it helps.

      @aisajib, I cleared the browser cache, and it didn’t solve the problem. I then switched browsers, from Chrome to Edge, and this time the cropping worked.

      But it would be unfortunate if I could not change the image headers while using Chrome…

      I have also uploaded the screenshot to media, in case something else could be done at WordPress.com to make this work with Chrome again.

      Thanks…

      @soberbanda31, I followed the instructions from aisajib, and cropping works now, but only with another browser.

      I looked up clearing the site cache, and apparently I can’t do that until I get the function enabled by an administrator (or a “Happiness Engineer” or whatever they’re calling it) at WordPress.com.

      I don’t want to play around with themes, because I can’t even find the one that I am using on the list. And I’m not sure anymore what the “default theme” is.

      I don’t think I have plugins to worry about.

      Thanks again…

      Hi there,

      To clarify image cropping continues to be an issue in Chrome, but works in Microsoft Edge?

      One thing I would like you to try is to visit your site in Chrome, but use an “incognito window” instead of a standard window. Once you have logged in to WordPress that way, are you able to crop your image?

      Also Can you visit this page and let us know what you see for “Operating System” and “Web Browser”?

      http://supportdetails.com/

      This will give us some extra troubleshooting info about your computer. Thanks for the additional info!

      @jerrysarcastic, you are correct regarding what I said before – that it was an issue with Chrome but not Microsoft Edge.

      I did what you recommended and visited using Chrome incognito, and it was not an issue.

      Then I went to my regular Chrome browser again and tried it again there, and as it turns out, the cropping function is working there too now.

      So I am hoping that the problem has been mysteriously solved.

      Thank you.

      Hi there!

      Glad to hear that it’s now solved! It sounds like it was a temporary browser issue.

      Let us know if you have more questions.

      I am having the same issue.
      The red lines that show where the image will be cropped is not displaying and after clicking “Crop Image” it reads “There has been an error cropping your image.”

      I’ve tried in Google Chrome, Google Chrome Incognito, Microsoft Edge, and Microsoft Edge InPrivate.

    • The topic ‘Error message cropping header image – it is not working’ is closed to new replies.

    There Has Been an Error Cropping Your Image WordPress

    Now and then when you alter a picture before the transfer, you will see the message There has been a mistake editing your picture. ‘WordPress mistake editing picture’ principally happens given the shortfall of the GD (Graphics Draw) bundle.

    Today, “There Has Been an Error Cropping Your Image WordPress”, At ARZHOST, let’s see what prompts this error and how our Hosting Expert Planners fix this for our clients.

    How does picture extra error look?

    WordPress offers the opportunity to construct sites, pastime web journals, and so on Henceforth it generally incorporates elements to transfer pictures. How about we investigate how the picture trimming error look.

    To transfer a picture to WordPress clients, utilize the choice “Select and Crop”. Then, at that point, change the yield determination, then, “There Has Been an Error Cropping Your Image WordPress”, at that point, select “Harvest Image”. At the point when things don’t work, it shows the message ‘There has been a mistake editing your picture’. Here, the WordPress “Media Library” becomes dark and results in a mistake.

    “There Has Been an Error Cropping Your Image WordPress”, The most widely recognized explanation prompting the mistake is feeling the loss of the PHP-GD library.

    Generally, when we catch wind of PHP in WordPress, the primary thing that we use to relate is HTML. However, PHP is additionally used to make and alter picture documents. Picture designs upheld incorporate GIF, PNG, JPEG, WBMP, and XMP. As a rule, PHP permits transferring a picture straightforwardly into the program. Also, it’s the GD library that makes picture capacities work.



    People Also Ask

    Question # 1: Why is there an error cropping image in WordPress?

    Answer: To upload an image in WordPress users use the option “Select and Crop”. Then adjust the crop selection, then select “Crop Image”. Here, the WordPress “Media Library” turns grey and results in an error. The most common reason leading to the error is missing the PHP-GD library.

    Question # 2: How do I stop WordPress cropping my photos?

    Answer: You can stop WordPress from generating default image sizes by visiting Settings » Media in the WordPress admin area. There you will see default image sizes predefined by WordPress. You need to set these sizes to 0 which will prevent WordPress from generating default image sizes when you upload a new image.

    Question # 3: How do I get featured images in WordPress?

    Answer: To add a featured image in a WordPress post, simply edit or create a new blog post. In the content editor, you’ll find the featured image tab in the right column. You need to click on the ‘Set Featured Image’ area, and this will bring up the WordPress media uploader popup.

    Question # 4: How do I enable featured images in custom post types?

    Answer: You can simply enable support Post thumbnail for any custom post type with the following line of code in the theme’s function. PHP file. add_post_type_support( ‘forum’, ‘thumbnail’ ); Note: Here, the forum is the post type name.

    Question # 5: How do I edit PHP in WordPress?

    Answer: Simply right-click on the file and then select download from the menu. Your FTP client will now download wp-config. PHP file to your computer. You can open and edit it using a plain text editor program like Notepad or Text Edit.



    How do we fix WordPress picture trimming mistakes?

    We currently realize how the mistake looks. “There Has Been an Error Cropping Your Image WordPress”, Continuing on additional we should mind how our Hosting Expert Planners fix picture trimming errors for our clients.

    As the initial step of investigating, we check the server’s PHP form alongside the GD bundle. If the GD bundle is missing, we introduce it. Notwithstanding, the GD establishment steps contrast contingent upon the server type.

    For Red Hat/CentOS has, we run the order

    • yum introduce php-gd

    Or on the other hand, “There Has Been an Error Cropping Your Image WordPress”, in case it is an Ubuntu server, GD establishment works utilizing

    • well-suited get introduce php-gd

    Here, our expert Team likewise ensures that the variant of the WordPress bundle coordinates with the PHP adaptation of the host. At long last, “There Has Been an Error Cropping Your Image WordPress”, to make the recently introduced GD bundle, the webserver needs a restart. We do this in the server by

    • /and so forth/init.d/httpd restart

    “There Has Been an Error Cropping Your Image WordPress”, After fixing the error, in the “Media Library,” the client can choose the picture and “Supplement into post”.

    Termination

    So, the primary justification behind the WordPress mistake trimming picture will be feeling the loss of the GD bundle on the server. Today, “There Has Been an Error Cropping Your Image WordPress”, we perceived how our Hosting Expert Planners check and fix picture transferring mistakes for our clients.

    I added wp.media via js to crop images. I’ve got it working for admin but not for any other role specifically ‘subscriber’. It sounds crazy but there are no errors at all in the console or in debug and the only error I get is There has been an error cropping your image.

    I don’t think its a GC issue or Imagick etc as it does work for admin.

    I’ve tried adding permissions to the ‘subscriber’ role: upload_files and edit_files (which seems to be deprecated anyways). Please help and thank you in advance! Here’s the code. I unfortunately do not know who to credit for this, but majority of it is not my original code:

    var mediaUploader;
                
                function myTheme_calculateImageSelectOptions(attachment, controller) {
    
                var control = controller.get( 'control' );
    
                var flexWidth = !! parseInt( control.params.flex_width, 10 );
                var flexHeight = !! parseInt( control.params.flex_height, 10 );
    
                var realWidth = attachment.get( 'width' );
                var realHeight = attachment.get( 'height' );
    
                var xInit = parseInt(control.params.width, 10);
                var yInit = parseInt(control.params.height, 10);
    
                var ratio = xInit / yInit;
    
                controller.set( 'canSkipCrop', ! control.mustBeCropped( flexWidth, flexHeight, xInit, yInit, realWidth, realHeight ) );
    
                var xImg = xInit;
                var yImg = yInit;
    
                if ( realWidth / realHeight > ratio ) {
                    yInit = realHeight;
                    xInit = yInit * ratio;
                } else {
                    xInit = realWidth;
                    yInit = xInit / ratio;
                }
    
                var x1 = ( realWidth - xInit ) / 2;
                var y1 = ( realHeight - yInit ) / 2;
    
                var imgSelectOptions = {
                    handles: true,
                    keys: true,
                    instance: true,
                    persistent: true,
                    imageWidth: realWidth,
                    imageHeight: realHeight,
                    minWidth: xImg > xInit ? xInit : xImg,
                    minHeight: yImg > yInit ? yInit : yImg,
                    x1: x1,
                    y1: y1,
                    x2: xInit + x1,
                    y2: yInit + y1
                };
    
                return imgSelectOptions;
            }
    
            function myTheme_setImageFromURL(url, attachmentId, width, height) {
                var choice, data = {};
    
                data.url = url;
                data.thumbnail_url = url;
                data.timestamp = _.now();
    
                if (attachmentId) {
                    data.attachment_id = attachmentId;
                }
    
                if (width) {
                    data.width = width;
                }
    
                if (height) {
                    data.height = height;
                }
    
                // $("#heading_picture").val( url );
                // $("#heading_picture_preview").prop("src", url);
    
                    $('[name="entry-img"]').val(attachmentId)
                    $('.activity-add-image').css({ 'background-image': `url(${url})` }).addClass('has-image')
                    $('.activity-remove-image').css('display', 'block');
                    fieldValidation.image.validated = true
                    validateNewLetter()
    
            }
    
            function myTheme_setImageFromAttachment(attachment) {
    
                // $("#heading_picture").val( attachment.url );
                // $("#heading_picture_preview").prop("src", attachment.url);
    
                    $('[name="entry-img"]').val(attachment.id)
                    $('.activity-add-image').css({ 'background-image': `url(${attachement.url})` }).addClass('has-image')
                    $('.activity-remove-image').css('display', 'block');
                    fieldValidation.image.validated = true
                    validateNewLetter()
    
            }
    
            $('.activity-remove-image').on('click', function(e){
    
                e.preventDefault();
                $('.activity-add-image').css({ 'background-image': 'none' }).removeClass('has-image')
                $('.activity-remove-image').hide();
                $('[name="entry-img"]').val(null)
                fieldValidation.image.validated = false
                validateNewLetter()
            });
    
            $(".activity-upload-image").on("click", function(e) {
    
                e.preventDefault();
    
                /* We need to setup a Crop control that contains a few parameters
                   and a method to indicate if the CropController can skip cropping the image.
                   In this example I am just creating a control on the fly with the expected properties.
                   However, the controls used by WordPress Admin are api.CroppedImageControl and api.SiteIconControl
                */
    
               var cropControl = {
                   id: "control-id",
                   params : {
                     flex_width : false,  // set to true if the width of the cropped image can be different to the width defined here
                     flex_height : false, // set to true if the height of the cropped image can be different to the height defined here
                     width : 1100,  // set the desired width of the destination image here
                     height : 460, // set the desired height of the destination image here
                   }
               };
    
               cropControl.mustBeCropped = function(flexW, flexH, dstW, dstH, imgW, imgH) {
    
                // If the width and height are both flexible
                // then the user does not need to crop the image.
    
                if ( true === flexW && true === flexH ) {
                    return false;
                }
    
                // If the width is flexible and the cropped image height matches the current image height,
                // then the user does not need to crop the image.
                if ( true === flexW && dstH === imgH ) {
                    return false;
                }
    
                // If the height is flexible and the cropped image width matches the current image width,
                // then the user does not need to crop the image.
                if ( true === flexH && dstW === imgW ) {
                    return false;
                }
    
                // If the cropped image width matches the current image width,
                // and the cropped image height matches the current image height
                // then the user does not need to crop the image.
                if ( dstW === imgW && dstH === imgH ) {
                    return false;
                }
    
                // If the destination width is equal to or greater than the cropped image width
                // then the user does not need to crop the image...
                if ( imgW <= dstW ) {
                    return false;
                }
    
                return true;
    
               };
    
                /* NOTE: Need to set this up every time instead of reusing if already there
                         as the toolbar button does not get reset when doing the following:
    
                        mediaUploader.setState('library');
                        mediaUploader.open();
    
                */
                    console.log('control', cropControl)
    
                mediaUploader = wp.media({
                    button: {
                        text: 'Select', // l10n.selectAndCrop,
                        close: false
                    },
                    states: [
                        new wp.media.controller.Library({
                            title:     'Select and Crop', // l10n.chooseImage,
                            library:   wp.media.query({ type: 'image' }),
                            multiple:  false,
                            date:      false,
                            priority:  20,
                            suggestedWidth: 1100,
                            suggestedHeight: 460
                        }),
                        new wp.media.controller.CustomizeImageCropper({
                            imgSelectOptions: myTheme_calculateImageSelectOptions,
                            control: cropControl
                        })
                    ]
                });
    
                mediaUploader.on('cropped', function(croppedImage) {
                            console.log('cropped', croppedImage)
                    var url = croppedImage.url,
                        attachmentId = croppedImage.attachment_id,
                        w = croppedImage.width,
                        h = croppedImage.height;
    
                        myTheme_setImageFromURL(url, attachmentId, w, h);
    
                });
    
                mediaUploader.on('skippedcrop', function(selection) {
                            console.log('skipped', selection)
                    var url = selection.get('url'),
                        w = selection.get('width'),
                        h = selection.get('height');
    
                        myTheme_setImageFromURL(url, selection.id, w, h);
    
                });
    
                mediaUploader.on("select", function() {
                    var attachment = mediaUploader.state().get( 'selection' ).first().toJSON();
                            console.log('select', attachment)
                    if (     cropControl.params.width  === attachment.width
                        &&   cropControl.params.height === attachment.height
                        && ! cropControl.params.flex_width
                        && ! cropControl.params.flex_height ) {
                            myTheme_setImageFromAttachment( attachment );
                        mediaUploader.close();
                    } else {
                                console.log(mediaUploader)
                        mediaUploader.setState( 'cropper' );
                    }
    
                });
    
                mediaUploader.open();
    
            });```
    

    Понравилась статья? Поделить с друзьями:
  • There has been a critical error on this website перевод
  • There has been a critical error on this website wordpress как исправить
  • There has been a critical error on this website learn more about troubleshooting wordpress
  • There from san francisco где ошибка
  • There are too much handlers казаки 2 ошибка