We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Using Image Sizer within conditional

Development and Programming

Antenna's avatar
Antenna
87 posts
16 years ago
Antenna's avatar Antenna

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

       
Scheffey's avatar
Scheffey
24 posts
about 16 years ago
Scheffey's avatar Scheffey

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.

       
eyevariety's avatar
eyevariety
158 posts
about 16 years ago
eyevariety's avatar eyevariety

I had the same problem before I updated, so give it a shot Antenna.

       
Antenna's avatar
Antenna
87 posts
about 16 years ago
Antenna's avatar Antenna

Thanks for the advice Scheffey and eyevariety - I’ll give it a try.

       
Joobs's avatar
Joobs
362 posts
15 years ago
Joobs's avatar Joobs

I have having the same problem with a conditional statement. But i don’t see how to do the blank image path check?

Can anyone post some example code?

       
Scheffey's avatar
Scheffey
24 posts
15 years ago
Scheffey's avatar Scheffey

Joobs, if you have the most recent version of imgsizer and you pass it a blank path it shouldn’t cause any errors. Can you check and see what version you have?

       
Joobs's avatar
Joobs
362 posts
15 years ago
Joobs's avatar Joobs

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)

       
Peter Lewis's avatar
Peter Lewis
280 posts
15 years ago
Peter Lewis's avatar Peter Lewis

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?

       
Joobs's avatar
Joobs
362 posts
15 years ago
Joobs's avatar Joobs
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"}

       
Aniden's avatar
Aniden
4 posts
15 years ago
Aniden's avatar Aniden
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

       
Peter Lewis's avatar
Peter Lewis
280 posts
15 years ago
Peter Lewis's avatar Peter Lewis

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.

       
Scheffey's avatar
Scheffey
24 posts
15 years ago
Scheffey's avatar Scheffey

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.

       
Joobs's avatar
Joobs
362 posts
15 years ago
Joobs's avatar Joobs

Yes Scheffey, i think this is exactly the problem.

I emailed the author about this “bug” a few days ago, but you might want to email him this code too so hopefully this is fixed in the next release.

       
m4thew's avatar
m4thew
21 posts
15 years ago
m4thew's avatar m4thew
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.

Superb fix, thank you!

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.