Timthumb workaround

Sometimes you have to use a theme that has timthumb deeply integrated. And sometimes when you use a theme like this and you’re using WordPressMU and you’re also using the Sitewide Tags plugin to push the posts to the front page. Normally I’d suggest ripping out timthumb and using Get the Image instead. It works well and it’s simpler, using WP’s internal thumbnails, or even a linked image in a post if you want.

But, like I said above, sometimes you’re stuck.

// in functions.php

function get_image_bid($url) {
$bid = 1;
if($url) {
$start = strpos($url, '//');
if($start > 0) {
$start += 2;
$end = strpos($url, '/', $start) - $start;
if($end > 0) {
$bid = get_blog_id_from_url(substr($url, $start, $end));
}
}
}
return $bid;
}

// in the image url

<img src=”<?php echo bloginfo(‘template_url’); ?>/scripts/timthumb2.php?src=<?php echo $image_src; ?>&amp;w=<?php echo $width; ?>&amp;h=<?php echo $height; ?>&amp;zc=1&amp;q=100&amp;bid=<?php echo get_image_bid($image_src); ?>”

If it helps someone finish up that project or stops them from banging their head, awesome. It was a one-time thing for me.

Using this a lot? The ever awesome @binarymoon is now working on keeping timthumb updated. He’s released a new beta version you can try.

If you’re theme developer, please consider strongly updating your timthumb usage. It’ll have to work with MU properly at some point.

Comments

  1. Hey Andrea,

    This is cool, I’ll have to check it out. I’m using Simpler Post Thumbnails which uses timthumb.php. The problem I’ve experienced is it can’t find the path to the image in MU. I created a modified version of timthumb that accepts the path if passed in and locates the image of that, also changed the cache to a global location. So far no problems.:)

    • can you explain what you did to make it work? i have a theme that uses timthumb extensively and i want it to work on mu, and your solution seems a lot simpler than trying to figure out how to switch from timthumb to get the image.

  2. Hi,
    It seems all the themes I like use timthumb and I don’t want to use it. How do you get replace remove timthumb, just delete the parts in your post? Sorry, I’m a Newbie! Thanks.

  3. Oops, please ignor my typo the word “get.”

  4. The CODE isnt wrapped in the code tags. could you fix it?

    om my mu blog i didnt get this to work it just added bid=1 at the end of the url…
    http://patrick.bloggbyen.com/files/2009/09/guru-josh-project-infinity.jpg&w=230&h=140&zc=1&q=100&bid=1

    image is there but its wrong path. because blog.id folder is stripped from the url

    • That help any? I can email it to you in plain text.

      • Yeah! That would be great if you could imail it. i have copied the code. downloaded the file from binarymoon and used the code in functions.php added &bid= to the end of my image code. but it doesnt display the file :(

  5. Hi,

    I am also having the same problem. I have WP MU set up in a sub directory of the main domain, so it is here:

    http://www.trashedmag.com/members/

    I need to be able to get the thumbnails working on both that url and ones as such:

    http://www.trashedmag.com/members/markjenkins

    I have the same problem where the /blog.dir/1/ is stripped out and it can’t find the image because it “doesn’t exist”

    I was wondering if anyone could give me some instructions on how to make the edits to the timthumb.php file please?

    thanks
    Mark

  6. How would you do the swap for “Get the Image”?

    Put that code in instead of timthumb.php ?

    Trying to get “Magazine Basic” to work with WPMU and having all sorts of headaches with the way MU re-writes the paths – even with the fixes that have been pointed out. Having the image resized properly for the front page of the site is key.

    Thx in advance….

    • I would so be grateful, I am struggling with this for 3 days now..

      You may be familiar with ElegantThemes.

      I am testing out this method in the featured slider first.

      I created the function as advised in functions.php and tried to replace the image src from
      <img src="/timthumb.php?src=&h=206&w=510&zc=1″ alt=”" width=”510px” height=”206px” />

      to

      <img src="/timthumb.php?src=&w=&h=&zc=1&q=100&bid=”
      per your instructions, but I am still not able to get it to work.

      Featured.php as it stands now is as follows…
      Note that $enews_grab_image == ‘off’) right now.

      ID, ‘Thumbnail’, $single = true); ?>

      <img src="/timthumb.php?src=&w=&h=&zc=1&q=100&bid=”

      |
      <a href="” title=”">

      ID;
      endwhile; wp_reset_query(); ?>



  7. Andrea_

    I am using the Arras Theme in WPMU and I am having an issue of getting the thumbs to appear on the home blog. (using TimThumb)

    The way the site is structured is that I have an umbrella site with three other blogs under it. The umbrella blog should pull the most recent posts from the three blogs. I am able to pull the posts but I haven’t had any luck getting the images. If I code the custom field to pull the thumb in the actual post it will not pull to the umbrella. If I view that post from the umbrella and then code the thumb custom field, the image will appear. I have a feeling that it has to do something with the file or folder structure.

    One other question that is not on this forum. I would like for my users, who register, to be able to access all three blogs including the umbrella. With WPMU, when the user registers they are only registered to that specific blog(and can only comment on that blog). I have been racking my brain for days trying to figure this out and you seem to be the only person that might have an idea.

    I’m just curious if you have any suggestions for me. Thanks in advance for your help.

  8. is there a simple way to fix this issue using the Arthemia theme on WordPress MU installation?

  9. appleseed says:

    Hi, this really makes me pull chunks of hair of my head!!
    And the people from themeforest whom I bought the theme from areto busy giving me direction on where to add the code!

    I aplogize for spamming your wall :D

    In the root of my theme there is a file named functions.php
    Looks like this

    as you can see in the code there is a folder named function where the above code calls for the named files.

    The timthumb.php is in the following direction
    themefolder/inc/timthumb.php

    the timthumb code i’m using is the one that Andrea linked to in the beginning of this article.
    http://www.binarymoon.co.uk/2009/07/timthumb-beta-test/

    I really need to get this timthumb thing to work

    Thanks a lot!

    Namaste/

    appleseed

  10. appleseed says:

    Hmm, here is the code from the funktion.php file

    I hope it works this time

Trackbacks