WordPress.org

Ready to get started?Download WordPress

Forums

Comment Images
[resolved] Size limit (22 posts)

  1. junger
    Member
    Posted 1 year ago #

    Great plugin! Is there a way to set a limit on the size of the images uploaded?

    The limit would be either dimensions or file size.

    Thanks!

    http://wordpress.org/extend/plugins/comment-images/

  2. tommcfarlin
    Member
    Plugin Author

    Posted 1 year ago #

    Thanks!

    Currently there is no way to set a limit on the size of the images being uploaded. I'll make a note of this and see about adding something like this in a future version.

  3. mcmillad
    Member
    Posted 1 year ago #

    I was having this problem also and changing the css for the plugin didn't work (noticed it was inactive after messing with it). I simply went in to my themes css and inserted the following code and it works great.

    /******************************************
    Comment Image Picture Control
    ******************************************/
    .comment-image img {
    max-width: 400px;
    }

    Of course just set the max-width to whatever looks good on your site. I hope this helps.

  4. tommcfarlin
    Member
    Plugin Author

    Posted 1 year ago #

    Thanks for sharing this. In the next version of the plugin, I plan to have this resolved.

  5. Li-An
    Member
    Posted 1 year ago #

    Very nice idea. But the best feature should be a resize of the uploaded image so the page will not be too heavy to load.

  6. tommcfarlin
    Member
    Plugin Author

    Posted 1 year ago #

    Noted - will see what I can do in a future version!

    Thanks for the suggestion!

  7. nootkan
    Member
    Posted 1 year ago #

    Awesome, thanks for this short term fix. Looking forward to the updated version of a great plugin.

  8. breadtopia
    Member
    Posted 1 year ago #

    Would also just like to second (or third or whatever) the motion to be able to auto downsize images so they fit the area. Would gladly purchase a reliable supported comment image upload plugin.

    Another awesome feature would be a lightbox type thing so double clicking a thumbnail image would expand it in pop up window.

  9. tommcfarlin
    Member
    Plugin Author

    Posted 1 year ago #

    Breadtopia,

    I hear you loud and clear!

    I always appreciate the feedback and I'm aiming to have these features baked in as soon as I can get some time.

    Also, I appreciate the thought on paying for a premium version of the plugin. That's something I'll definitely consider.

    Love all the feedback - keep it coming!

  10. breadtopia
    Member
    Posted 1 year ago #

    Sounds good. Just having a receptive developer is a bonus!

    I've been through a few comment image plugins that either aren't quite good enough and/or no longer supported. Such a plugin is invaluable for our site so I'm surprised there there doesn't seem to be more demand for it.

    Since the beginning I've had to use a programmer to add code or whatever to get them to do what I want. Having just discovered yours, they are working on it as I type. Hopefully they'll also get it to pull in all the previously uploaded images from the now defunct plugin I was using.

  11. tommcfarlin
    Member
    Plugin Author

    Posted 1 year ago #

    Completely understand.

    I'd love for this to be the de-facto Comment Images plugin, but I've just gotta find the time to work in these feature requests.

    Believe me: I'm just as impatient as you guys when it comes to want it done ;). Just have a backlog of some other stuff for the time being.

  12. gnickoloff
    Member
    Posted 1 year ago #

    Just thought I'd "bump" this thread... I could use the image re-sample function.
    Thanks for great work!

  13. tommcfarlin
    Member
    Plugin Author

    Posted 1 year ago #

    Thanks gnickoloff!

    This hasn't been forgotten - just haven't had a chance to work on the plugin lately.

    For those that are curious, this is likely how the plugin will work:

    • On each post's page, you'll set a maximum size for the image (in MB)
    • The comment form will display a note, if there is a limit
    • If the image uploaded is greater than the size specified, then the user will be given a warning and the image will fail to load

    Hope this clarifies where things are heading (at least in the future :).

  14. ianarmstrong
    Member
    Posted 1 year ago #

    Haven't had time in ten months? You've got a very popular plugin man, at least stick it on Git and request a fork.

  15. tommcfarlin
    Member
    Plugin Author

    Posted 1 year ago #

    @ianarmstrong

    The plugin hasn't not been updated; however, this is one feature I just haven't gotten to implementing yet.

  16. ianarmstrong
    Member
    Posted 1 year ago #

    Good to know. I can get it to die if I do a file check but it does an ugly die and then posts the comments with the image stripped anyway. It's sub-optimal. I can remove the else and it posts the comment but silently strips the image.

    // If the nonce is valid and the user uploaded an image that is less than 150kb, let's upload it to the server
    		if( isset( $_FILES[ $comment_image_id ] ) && ! empty( $_FILES[ $comment_image_id ] ) ) {
                if ( $_FILES[ $comment_image_id ]['size'] < 153600 ) {
    
                    // Store the parts of the file name into an array
                    $file_name_parts = explode( '.', $_FILES[ $comment_image_id ]['name'] );
    
                    // If the file is valid, upload the image, and store the path in the comment meta
                    if( $this->is_valid_file_type( $file_name_parts[ count( $file_name_parts ) - 1 ] ) ) {;
    
                        // Upload the comment image to the uploads directory
                        $comment_image_file = wp_upload_bits( $_FILES[ $comment_image_id ]['name'], null, file_get_contents( $_FILES[ $comment_image_id ]['tmp_name'] ) );
    
                        // Now, we need to actually create a post so that this shows up in the media uploader
                        $img_url = media_sideload_image( $comment_image_file['url'], $post_id );
    
                        // And strip out the name of the image file so we can save this to the meta data
                        // Regex is usually bad for this, but WordPress is predictable in the format
                        preg_match_all( "#[^<img src='](.*)[^'alt='' />]#", $img_url, $matches );
                        $comment_image_file['url'] = $matches[0][0];
    
                        // Set post meta about this image. Need the comment ID and need the path.
                        if( false == $comment_image_file['error'] ) {
    
                            // Since we've already added the key for this, we'll just update it with the file.
                            add_comment_meta( $comment_id, 'comment_image', $comment_image_file );
    
                        } // end if/else
    
                    } // end if
    
                } else { die; }
            }
  17. ianarmstrong
    Member
    Posted 1 year ago #

    Hey Tom,

    Enqueue this to the footer of comments.php (or ideally just hook it) and think about adding a theme option for file size.

    <script>
        document.forms[0].addEventListener('submit', function( evt ) {
            var file = document.getElementById('comment_image').files[0];
    
            if(file && file.size < 153600) { // 150k (this size is in bytes)
                //Submit form
            } else {
                //Prevent default and display error
                alert('File size is too large, please reduce and try again');
                evt.preventDefault();
            }
        }, false);
    </script>

    That does the trick.

    Also, in plugin.php, consider modifying the display code:

    <a href="' . $comment_image['url'] . '" rel="PrettyPhoto"><img src="' . $comment_image['url'] . '" alt="" /></a>

    The rel won't do a thing if PrettyPhoto isn't installed but if it is, it'll trigger the plugin. You can ignore that or make it an option but the link to full size is nice.

    Finally, the following CSS:

    p.comment-image img {max-width: 45%;}
    span.warning {color:indianred;}

    In addition to a warning:
    $html .= __( '<br><span class="warning">File must be smaller than 150k or submit will fail</span>', 'comment-images' );

    Makes a it a much more functional tool.

    Cheers.

  18. tommcfarlin
    Member
    Plugin Author

    Posted 1 year ago #

    Thanks for sharing the code, Ian. For those that need this, this'll be a viable option.

    Ultimately, my plan to make it a bit more flexible through the use of a setting, an option page, and so on; however, there are some parts of the core of the plugin that I want to improve first.

    This is definitely a viable short term solution so I appreciate you taking the time to share it here!

  19. ianarmstrong
    Member
    Posted 1 year ago #

    I went over the script with my PHP guy and we decided that, without restructuring your logic a bit, it would be difficult to make the kinds of changes I wanted in a practical way. Ideally, the plugin would invoke the WP media uploader and display a resized thumbnail in the comment body.

    The JS solution made a nice stopgap though and I hope someone finds it useful :)

    For now, combined with NicEdit, it creates a much slicker interface than what is presented by default.

    http://imperativeideas.com/dev/final.png

  20. roland_susan
    Member
    Posted 1 year ago #

    Hi, I have the same problem with the very good comment images plugin. I want to set a limit on the size of the images uploaded.
    I tried with

    <script>
        document.forms[0].addEventListener('submit', function( evt ) {
            var file = document.getElementById('comment_image').files[0];
    
            if(file && file.size < 153600) { // 150k (this size is in bytes)
                //Submit form
            } else {
                //Prevent default and display error
                alert('File size is too large, please reduce and try again');
                evt.preventDefault();
            }
        }, false);
    </script>

    at the end of comments.php but I can not make it work.
    I use the latest version of worpress and Webfolio Theme.

    Any idea that this solution is working for me? Thank you and sorry for my google english.

  21. roland_susan
    Member
    Posted 1 year ago #

    I stand corrected. The code works perfectly.
    In twenty twelve theme and I suppose in other wordpress.

    The problem is the theme I use, Webfolio.

    Do not get it to work there.

    Anyone know what can be wrong?
    Thanks and apologies for the misunderstanding.

  22. roland_susan
    Member
    Posted 1 year ago #

    hello,
    I correct myself.

    The problem with the theme Webfolio was silly, "document.forms [1]" instead of "document.forms [0]".

    the problem of error image is added, I fixed it by adding a couple of lines. To see what you think:

    <script>
        document.forms[1].addEventListener('submit', function( evt ) {
            var file = document.getElementById('comment_image').files[0];
    
            if(file && file.size < 153600) { // 150k (this size is in bytes)
                //Submit form
            } else if (!file){
    			//Submit form
    		} else {
                //Prevent default and display error
                alert('Tu imagen tiene un tama\u00f1o superior a 150Kb, reduce su tama\u00f1o o env\u00edanosla por email.');
    			document.getElementById('comment_image').value = '';
                evt.preventDefault();
            }
        }, false);
    </script>

    works for me, let me know if you see any corrections.

    Greetings!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.