Image resize doubling slashes

drewgg
14 years, 8 months ago
Joomla version: 1.5.20
Mobile Joomla! version: 0.9.7
PHP version: 5.2.8

A number of images were broken on the mobile version of the site I was testing. I narrowed it down to images that are being resized. The URL after resize always started off with slashes (//) instead of one:

<img [snip] src="//images/stories/Resized/imagename_240x253.jpg" />

It happens regardless of whether the original image URL is relative or absolute. The culprit is in /administrator/components/com_mobilejoomla/imagerescaler.class.php line ~180:

 
$dest_imageuri = $base_rel.implode('/', explode(DS, substr($dest_imagepath, strlen(JPATH_SITE))));
 


If the image's path ($dest_imagepath) is:

/home/sitepath/public_html/images/stories/Resized/imagename_240x253.jpg

Then the substr() will shorten it to

/images/stories/Resized/imagename_240x253.jpg

The explode() will result in an array like this:

 
Array (
[0] =>
[1] => images
[2] => stories
[3] => Resized
[4] => imagename_240x253.jpg
)
 


And finally the implode() will result in this:

//images/stories/Resized/imagename_240x253.jpg

Which is what is returned as the URI path ($dest_imageuri).

Is this a known issue? I would think something like this would have been picked up and fixed a during initial testing, considering it breaks all resized images...

Either way, my solution was to simply check for double slashes and remove one them if found:

 
$dest_imageuri = $base_rel.implode('/', explode(DS, substr($dest_imagepath, strlen(JPATH_SITE))));
$dest_imageuri = str_replace("//", "/", $dest_imageuri);
 
dryabov
14 years, 8 months ago
drewgg, thanks for report. Will be fixed in 0.9.8 soon.
drewgg
14 years, 8 months ago
coolies. Thanks!
drewgg
14 years, 8 months ago
Just to let you know, I changed my patch to simply add 1 to the strlen(JPATH_SITE):

 
$dest_imageuri = $base_rel.implode('/', explode(DS, substr($dest_imagepath, strlen(JPATH_SITE)+1)));
 
dryabov
14 years, 8 months ago
In SVN we changed it to
$dest_imageuri = $base_rel.implode('/', explode(DS, substr($dest_imagepath, strlen(JPATH_SITE.DS)))); 

(it seems more clear)
drewgg
14 years, 8 months ago
I agree
totalfanshop
14 years, 7 months ago
Thanks for the code fix. I had the issues and your fix worked great!

Just installed this on my site and love it!

Looking forward to more

Dan
Gam3sfa
14 years, 7 months ago
Someone I can pass the file already done? because the images are not seen.

By continuing to use this site you consent to the use of cookies on your device as described in our cookie policy unless you have disabled them. This site will not function correctly without cookies.

I accept cookies from this site.