WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Default thumbnail extension changed. (20 posts)

  1. twistedsymphony
    Member
    Posted 6 years ago #

    WP 2.5 changed the default file extension for thumbnail images which was *.thumbnail.jpg in WP 2.3 and is now *.HHH-WWW.jpg

    The problem is my site (http://collectorsedition.org) uses a plugin (that I wrote) to grab the thumbnail image from the name of the original image.

    It's now broken for all newly uploaded images because I don't know what the thumbnail image is.

    Before I could always assume it was .thumbnail.jpb but now I don't know what it is because it's .???-150.jpg

    I can modify the wordpress files to "fix" this but I'd rather not because then I have FIX it every time I upgrade. Is there some way I can modify my plugin to know what the thumbnail image from the name of the original file? I needs to work with the 300+ images that I've already uploaded with the .thumbnail extension as well as the newly uploaded files.

  2. twistedsymphony
    Member
    Posted 6 years ago #

    Can anyone help with this?

    I'd be happy enough with a function that generates the html for the thumbnail and fullsized image link from the file name or post id or something...

  3. twistedsymphony
    Member
    Posted 6 years ago #

    PLEASE ANYONE... I've been pulling my hair out over this and it's essentially holding my site hostage until it's fixed!

  4. elfin
    Moderator
    Posted 6 years ago #

    This is most certainly a hack but I managed to get around this by using the following:

    $attargs = array(
    'post_type' => 'attachment',
    'numberposts' => null,
    'post_status' => null,
    'post_parent' => $post->ID
    );
    $attachments = get_posts($attargs);
    if ($attachments) {
    foreach ($attachments as $attachment) {
    $img_url= wp_get_attachment_thumb_url($attachment->ID);
    
    $chkimg=wp_get_attachment_url($attachment->ID);
    if($img_url==$chkimg){
    $img_url = preg_replace('!(\.[^.]+)?$!', __('.thumbnail') . '$1', $img_url, 1);
    }else{
    $img_url = wp_get_attachment_thumb_url($attachment->ID);
    }
    $echo .='<a class="itemref" href="'.get_permalink($post->ID).'"><img src="'.$img_url.'" alt="'.apply_filters('the_title', $attachment->post_title).'" /></a>';
    
    break;
    }
    }

    don't know if that helps, or if there is a better way.

  5. twistedsymphony
    Member
    Posted 6 years ago #

    Where exactly are you using this? It looks like that would echo thumbnails with links for every attachment associated with the current post?

    Not exactly what I'm looking for, but thanks for the response.

    Basically I have a page, and I have meta tag with an image name and sub directory. the image might not even be associated with the current page at all. Then I have some code that looks at the specified image and echos html to display the thumbnail of that image (by simply adding .thumbnail before the extension) as well as makes the image a clickable link to the full sized image.

    I can't believe there is no function I can use to just say "echo the html to display the thumbnail and a link to the fullsized" How does WP do it when I tell it to insert a thumbnail into my post?

    Over the last three years I've submitted maybe a half dozen support questions, all of them dealing with things that aren't answered in the documentation (I wouldn't want to waste people's time with questions I could answer myself) and only ONCE have I received a helpful response and that was for an issue that was up for OVER A YEAR.

    The complete absence of a response from any of the staff makes me feel like a fool for having donated as much as I have to this software team. :(

  6. elfin
    Moderator
    Posted 6 years ago #

    The new image uploads don't add 'thumbnail', as you've pointed out so I use the above to check for old and new images.

    I use it in my plugin to set a thumbnail per page, or show the first one uploaded via that page.

  7. Antonio
    Member
    Posted 6 years ago #

    hey twistedsymphony,
    had exactly the same problem as you...
    the image_resize function is defined in wp-includes\media.php, line 178, as ibear pointed out here.

    There you should be able to mess with the suffix system as I'm doing right now.

  8. twistedsymphony
    Member
    Posted 6 years ago #

    thanks for the link dardna, I've read ibear's post once before and it's really a hack... having to modify core wordpress files isn't really a solution I would like to implement. though it's looking increasingly that I might have to.

  9. mores
    Member
    Posted 6 years ago #

    Thanks elfin.
    I used the checking/comparing/replacing part of your code in a plugin by walter vos called "easygals", and it allowed me to get his plugin working with WP 2.5

    Thanks! My site is not screwed up anymore :)
    (Instead of thumbnails I had the full size images attached which made the site really long.)

  10. mores
    Member
    Posted 6 years ago #

    I actually modified that plugin so much that I released it as EasyPermGals, if anyone's interested.

  11. scotjam
    Member
    Posted 6 years ago #

    This problem with the suffix for images still exists in 2.6. I thought it might have got sorted, but any ideas on what code I need to change in media.php to get this fixed? I'd like to revert to the old way of naming images, e.g. *.thumbnail.jpg

    please help!

  12. Anonymous
    Unregistered
    Posted 6 years ago #

    This works for me (but please make a backup of the files before!):

    wp-admin/includes/media.php (about ll. 605)
    replace

    $edit_post = sanitize_post($post, 'edit');
    	$file = wp_get_attachment_url($post->ID);
    	$link = get_attachment_link($post->ID);

    with

    $edit_post = sanitize_post($post, 'edit');
    	$file = wp_get_attachment_url($post->ID);
            $medium = ereg_replace(".jpg","-medium.jpg",$file);
    	$link = get_attachment_link($post->ID);

    wp-admin/includes/media.php (about ll. 635)
    replace

    <button type='button' class='button url-$post->ID' value=''>" . __('None') . "</button>
    				<button type='button' class='button url-$post->ID' value='" . attribute_escape($file) . "'>" . __('File URL') . "</button>
    				<button type='button' class='button url-$post->ID' value='" . attribute_escape($link) . "'>" . __('Post URL') . "</button>

    with

    <button type='button' class='button url-$post->ID' value=''>" . __('None') . "</button>
    				<button type='button' class='button url-$post->ID' value='" . attribute_escape($file) . "'>" . __('File URL') . "</button>
                                    <button type='button' class='button url-$post->ID' value='" . attribute_escape($medium) . "'>Medium</button>
    				<button type='button' class='button url-$post->ID' value='" . attribute_escape($link) . "'>" . __('Post URL') . "</button>

    wp-includes/media.php (about ll. 224)
    replace
    $suffix = "{$dst_w}x{$dst_h}";
    with

    if($max_w == get_option('thumbnail_size_w') || $max_h == get_option('thumbnail_size_h')) { $suffix = "thumb"; }
             elseif($max_w == get_option('medium_size_w') || $max_h == get_option('medium_size_h')) { $suffix = "medium"; }
             else { $suffix = "{$dst_w}x{$dst_h}"; }

    Now you get two thumbnails: a small one (filename-thumb.jpg) and a medium one (filename-medium.jpg). You can change the size in the WordPress config.
    It would be great if anyone could pack that into a plugin.

    Viele Grüße und sorry for my bäd English!

  13. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    Why in the heck are you going to all this trouble? The thumbnail names are stored in the attachment metadata just like the original image name is.

    $meta = wp_get_attachment_metadata( $attachment_post_id );
    echo $meta['thumb'];

    Or heck, even better:
    echo wp_get_attachment_thumb_url( $attachment_post_id );

    Why all the hardship? WordPress has functions to do all this stuff. All you need is the post_id of the attachment.

  14. Anonymous
    Unregistered
    Posted 6 years ago #

    All you need is the post_id of the attachment.

    I don't want to learn the ids of my uploaded pictures by heart ;) . Also you can't use that function within a post, can you?

    After having uploaded a picture I like to insert the thumbnail with the link to the medium-sized version. Normally wordpress just gives various figures as filename.

    Besides, I worked 30 minutes on that solution, so I'm going to keep it. :)

  15. scotjam
    Member
    Posted 6 years ago #

    thanks acrylschaf, I'll give this a try. appreciate the help. cheers

  16. twistedsymphony
    Member
    Posted 5 years ago #

    thank you Otto42, that was pretty much the solution I was looking for at the beginning but I couldn't find it documented anywhere and no one seemed to know about it either.

    I'll look into that and see if I can get it to do what I need it to do :)

  17. Phoat
    Member
    Posted 5 years ago #

    My problem with the new naming system is that I set the dimensions of the medium size image so that it fits my design. When I insert an image, the image is hardcoded into the post.

    If I decide to change the design, I would need to regenerate the thumbnails/medium images to fit the new design (there are plugins that do this). With the naming conventions as is however, the hardcoded images would break.

    If the filenames were still file-thumbnails.ext or file-medium.ext this wouldn't be an issue.

    I think the developers should add an option so that the user is able to choose the naming convention of thumbnails along with a function that will rebuild thumbnails/medium images according to the media settings.

    Is there a way to change the default naming of thumbnails through a plugin?

  18. twistedsymphony
    Member
    Posted 5 years ago #

    Phoat, if you change the design of your site... and the setting for the sizing of medium and thumbnail images it wouldn't matter what the name of the file is in your post... because you'd have to go back through and regenerate all of the medium and thumbnail images ANYWAY... think about it, it's not done on the fly, it's done on upload... at that point changing the file name is trivial.

    As a personal update, I've been using the method outlined by Otto42 above and it's worked exactly as I've needed it. Thanks again.

  19. kountz
    Member
    Posted 5 years ago #

    @twistedsymphony,

    How did you get it to work??
    How do you find the first image $attachment_post_id from the $post->ID?
    So that i get the first image attachment from a post.

    I'm so close i can feel it! :P

  20. Phoat
    Member
    Posted 5 years ago #

    twistedsymphony,

    As I said in my post, there are plugins that regenerate the thumbs and medium images based on the settings you specify in the media settings.

    This plugin is an example that regenerates thumbnails after you've uploaded them.

    http://www.viper007bond.com/wordpress-plugins/regenerate-thumbnails/

Topic Closed

This topic has been closed to new replies.

About this Topic