Hi,
I’m using the Image Sizer plugin within conditional variables like this:
{if image1}
{exp:imgsizer:size image="{image1}" width="404" height="276" alt="{image1-alt}" {if image1-title}title="{image1-title}"{/if} class="image" }
{/if}
{if image2}
{exp:imgsizer:size image="{image2}" width="404" height="276" alt="{image2-alt}" {if image2-title}title="{image2-title}"{/if} class="image" }
{/if}
…but if there is no ‘image2’ I get this error within the page when viewing the website:
Notice: Undefined index: path in /home/nas05l/p/mysite.com/user/htdocs/sitebox/plugins/pi.imgsizer.php on line 116
Notice: getimagesize() [function.getimagesize]: Read error! in /home/nas05l/p/mysite.com/user/htdocs/sitebox/plugins/pi.imgsizer.php on line 151
Does anyone have any ideas what’s happening here and how I can fix it?
Many thanks,
Andy
Not sure if you are still having this problem since it has been a couple weeks since your post.
The imgsizer tag runs its process before the “if” statement. So you can’t stop it from running with the “if” statement, you can only keep it from displaying the results.
Based on your syntax it looks like you might be running an older version of imgsizer. Version 2.5.6 (http://www.lumis.com/page/imgsizer/) includes checks for blank image paths. Of course if you update then you’ll need to update your imgsizer calls.
I am using 2.5.6
Here is an example of the code i am using, I haven’t touched this code since the previous version
{if avatar_filename}{exp:imgsizer:size src="{avatar_url}{avatar_filename}" width="170" height="170" alt="{screen_name}'s avatar"}{if:else}{exp:imgsizer:size src="images/site/noavatar.jpg" width="170" height="170" alt="no avatar"}{/if}
the error i get is:
Notice: getimagesize() [function.getimagesize]: Read error! in /serverpath/system/plugins/pi.imgsizer.php on line 151
(happens for each image that doesn’t have an avatar/path)
The first code you posted had an if statement inside the extension declaration, which won’t work.
This should work (if title doesn’t exist it would be blank):
{if image1}
{exp:imgsizer:size image="{image1}" width="404" height="276" alt="{image1-alt}" title="{image1-title}" class="image" }
{/if}
{if image2}
{exp:imgsizer:size image="{image2}" width="404" height="276" alt="{image2-alt}" title="{image2-title}" class="image" }
{/if}
For the second code you posted does {avatar_url}{avatar_filename} exist and when displayed is the URL formed correctly?
Usually if the image isn’t found there’s no error, it just doesn’t display anything, so the issue is probably something else or down to your server.
You need to identify which image is causing the problem, test it with only 1 of the imgsizer calls and see which is causing the issue.
“images/site/noavatar.jpg” has no initial “/”, could this be an issue? Is the path correct?
For the second code you posted does {avatar_url}{avatar_filename} exist and when displayed is the URL formed correctly? Usually if the image isn’t found there’s no error, it just doesn’t display anything, so the issue is probably something else or down to your server. You need to identify which image is causing the problem, test it with only 1 of the imgsizer calls and see which is causing the issue.
Yeah, {avatar_url} is a path variable so it’s being parsed into imgsizer and this is causing the error.
The error occurs if you use a directory as the “src=” rather than a file name.
So for example putting a directory path in image sizer causes the error: {exp:imgsizer:size src="images/site/"}
Putting a path to a file that doesnt exist seems to be fine though: {exp:imgsizer:size src="images/site/file_doesnt_exist.jpg"}
Yeah, {avatar_url} is a path variable so it’s being parsed into imgsizer and this is causing the error. The error occurs if you use a directory as the “src=” rather than a file name. So for example putting a directory path in image sizer causes the error: {exp:imgsizer:size src="images/site/"} Putting a path to a file that doesnt exist seems to be fine though: {exp:imgsizer:size src="images/site/file_doesnt_exist.jpg"}
I have the same problem as Joobs. imgsizer shouldn’t even be initiated when the conditional does not match, yet it does. Even combining the final ‘url’ as an assign_variable doesn’t work around this.
Any help would be greatly appreciated.
Thanks.
David
Can you strip it down to isolate the issue line, so just:
{if avatar_filename}Avatar_filename={avatar_filename}{/if}
Does this display when avatar_filename doesn’t equal anything? If this is working OK, then it sounds like a parsing issue - EE is implementing all the extensions first before deciding if the extension output should be displayed. So imgsizer pulls back an error even though the output won’t be displayed.
On this assumption, try dumping in a embed template.
{if avatar_filename}
{embed="include/avatar-resize" image-url="{avatar_url}{avatar_filename}" name="{screen_name}"}
{if:else}
{embed="include/avatar-resize" image-url="images/site/noavatar.jpg" name="no avatar"}
{/if}
Inside the embed template (in this example the template is include/avatar-resize):
{exp:imgsizer:size src="{embed:image-url}" width="170" height="170" alt="{embed:name}'s avatar"}
David - can you post your code.
The plugin will run before the IF statements, so those are irrelevant here. The plugin will just end up running twice and then the code will later decided which result to use in the IF statement.
I think that what may be happening is that you are passing in a partial path (ex: “img/avatars/”) into imgsizer instead of a full path ex: “img/avatars/pic.jpg”). This will cause an error.
I had a similar issue and made the following modification around line 134 in the code
if(strrpos($img['src'], "/") == (strlen($img['src'])-1)){
$TMPL->log_item("imgsizer.Error: image source is blank");
return $TMPL->no_results();
}
This should go right after the line which looks like this:
if($remote && $img['url_src']){
$img['src'] = $this->do_remote($img);
}
The code modification checks to see if a slash is the last character in the file path. If a slash is the last character, then you’ve only passed in a directory path and not a full path to an image, so it logs the error and prevents the rest of the code from running. This is similar to how the code handles blank image paths.
Hopefully this does the trick.
The plugin will run before the IF statements, so those are irrelevant here. The plugin will just end up running twice and then the code will later decided which result to use in the IF statement. I think that what may be happening is that you are passing in a partial path (ex: “img/avatars/”) into imgsizer instead of a full path ex: “img/avatars/pic.jpg”). This will cause an error. I had a similar issue and made the following modification around line 134 in the codeThis should go right after the line which looks like this:if(strrpos($img['src'], "/") == (strlen($img['src'])-1)){ $TMPL->log_item("imgsizer.Error: image source is blank"); return $TMPL->no_results(); }
The code modification checks to see if a slash is the last character in the file path. If a slash is the last character, then you’ve only passed in a directory path and not a full path to an image, so it logs the error and prevents the rest of the code from running. This is similar to how the code handles blank image paths. Hopefully this does the trick.if($remote && $img['url_src']){ $img['src'] = $this->do_remote($img); }
Superb fix, thank you!
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.