Reputation: 1310
I'm writing a wordpress plugin, and using this script to resize images: Timthumb
This script uses absolute paths, but I can't get it to work for me; I've triple-checked all my paths but still nothing.
Here is my code:
$plugin_dir_name = "my-plugin";
$pathTimThumb = WP_PLUGIN_URL . '/' . $plugin_dir_name . '/timthumb.php';
$pathToUpload = WP_CONTENT_URL.'/uploads/'.$plugin_dir_name;
$hImg = 150;
$wImg = 150;
....
$myImage = '<img class="thumb" src="'.$pathImageThumb.'?src='.$pathToUpload.'/'.$allImages[$i].'&h='.$hImg.'&w='.$wImg.'&zc=1" alt="">';
In firebug I get this URL:
<img alt="" src="http://localhost/mu/wp-content/plugins/my-plugin/timthumb.php?src=http://localhost/mu/wp-content/uploads/my-plugin/car___1/26zhoar5.jpg&h=150&w=150&zc=1" class="thumb">
Where is the mistake?
Upvotes: 0
Views: 2854
Reputation: 522
use this one.
$my_plugin_url = plugins_url('my-plugin-name/');
$my_timthumb_url = $my_plugin_url.'timthumb.php?';
$my_image_url = 'http://localhost/images/image.jpg';
echo '<img alt="" src="'.$my_timthumb_url.'src='.$my_image_url.'&h=150&w=150&zc=1"/>';
things to consider to make timthumb work:
Cheers,Dave
Upvotes: 1
Reputation: 9997
TimThumb tries to determine the local path of the image by stripping out http://CURRENT_HOST.tld
from the beginning of the src
parameter.
Since you're running on localhost
it might be getting a little confused and falsely calculating it as an external image. I doubt this is the case (I checked the source and it should be OK), but it's an educated guess.
Have you tried reading the HTTP response headers from http://localhost/mu/wp-content/plugins/my-plugin/timthumb.php?src=http://localhost/mu/wp-content/uploads/my-plugin/car___1/26zhoar5.jpg&h=150&w=150&zc=1
?
If not, use HttpFox for FireFox and post back the results.
Upvotes: 0
Reputation: 4581
WP_CONTENT_URL
is a url, not an absolute path. Use WP_CONTENT_DIR
instead.
Upvotes: 0