• Image thumbnails name used to look like mypicture.thumbnail.jpg before WP 2.7

    Now, instead, the name looks like mypicture-150×150.jpg (where 150×150 is the default width x height setted by admin panel) and mypicture-mediumWidthXgeneratedHeight.jpg so…I can’t call directly these images by a custom field, because I can’t know one of the two dimensions.

    Well…hope you understand what I mean, and it’s strange I’ve found only this post about (I wrote a comment there, but no answer)

    That solution works for half, because I lost “Middle size” and “Thumbnail” images.

    Any idea? Maybe there is another way to call resided images (now I’m using custom fields)

    Thank you for your help

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter teonsight

    (@teonsight)

    I created this workaround to solve the problem. Basically I use the WP function “image_resize_dimensions” which calculates the dimensions of a resized image, according to Settings->Media numbers.

    My workaround is supposed to be used with images that contain no other dots except the one for the extension: i.e. my.picture.jpg doesn’t work, while my-picture.jpg works.

    Finally…here is the code:

    //Gets the custom field of the post
    $strSrcImgName = get_post_meta($post->ID, ‘img_main’,1);
    
    //Gets dims of the original image
    list($orig_w, $orig_h) = getimagesize( $_SERVER["DOCUMENT_ROOT"].get_option(’upload_path’).’/’.$strSrcImgName );
    
    //Calculates dims of the “medium size” resized image
    list($dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) = image_resize_dimensions($orig_w, $orig_h, get_option(’medium_size_w’), get_option(’medium_size_h’), false);
    
    //..here it is why it doesn’t work with images with more than one dot
    $aImgName = explode(’.',$strSrcImgName);
    $strMediumImgName = $aImgName[0].’-’.$dst_w.’x’.$dst_h.’.’.$aImgName[1];

    Hey, im happy someone has been experiencing a similar problem as I, and like my fellow wordpresser above i am surprised that there is not much documentation yet on this subject. I do believe that in some circumstances, the dimensions on the of the image appended to the end of the image file name can present issues for blogs or sites using the image name in custom fields. For example, The site that I have been working on I found it most appropriate to use a custom field to save the image name as post metadata, and then call one of the three various sizes of that picture, depending how the post is formatted in that particular section of the site.

    I have been able to get around the issues for now as i have just called the metadata and added to an inline css background declaration, such as

    <div style="background:url(images/<?php echo $thepicname; ?>-100x66.jpg)......">
    However, this method relies on the image being uploaded at specific dimensions each time, which is fine for me, but not so much for the other less computer literate coworkers of mine.

    Thank you teonsight for posting your workaround, i will give it a try ??

    If you are unsure what I mean, please check out https://kayvontv.com to take a look.

    I agree completely. This has wasted so much of my time.

    I also need to call the three different image sizes but because the new naming convention is variable that is now impossible.

    I don’t want to hack the file that is responsible for naming these images but I see no other way…

    I managed to get it to work with this code (this will create the url for the thumbnail-image):
    $a_id = get_post_meta($post->ID, ‘attachment_id’, true);
    $size = ‘thumbnail’;
    $image_src_array = wp_get_attachment_image_src($a_id, $size);
    //get url – 0 – url; 1 and 2 are the x and y dimensions
    $url = $image_src_array[0];
    echo $url;

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘WP 2.7 and image thumbnails name’ is closed to new replies.