EllisLab text mark
Advanced Search
     
Using Image Sizer within conditional
Posted: 06 July 2009 06:29 AM   [ Ignore ]
Avatar
Joined: 2006-03-24
120 posts

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

 
Posted: 17 August 2009 04:10 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2005-10-03
27 posts

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.

 Signature 

Andy Mathers
Senior Interactive Designer
Scheffey Integrated Marketing
phone: 717.569.8274 x34
350 New Holland Avenue
Lancaster, PA 17602
.(JavaScript must be enabled to view this email address)
http://www.scheffey.com

 
Posted: 17 August 2009 04:49 PM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-28
175 posts

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

 Signature 

twitter

 
Posted: 17 August 2009 05:06 PM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2006-03-24
120 posts

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

 
Posted: 17 September 2009 01:24 PM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Joined: 2007-07-04
459 posts

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?

 
Posted: 17 September 2009 02:19 PM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2005-10-03
27 posts

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?

 Signature 

Andy Mathers
Senior Interactive Designer
Scheffey Integrated Marketing
phone: 717.569.8274 x34
350 New Holland Avenue
Lancaster, PA 17602
.(JavaScript must be enabled to view this email address)
http://www.scheffey.com

 
Posted: 18 September 2009 05:58 PM   [ Ignore ]   [ # 6 ]   [ Rating: 0 ]
Joined: 2007-07-04
459 posts

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)

 
Posted: 19 September 2009 05:34 AM   [ Ignore ]   [ # 7 ]   [ Rating: 0 ]
Avatar
Joined: 2007-10-17
297 posts

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?

 Signature 

twobelowzero
EE add-ons support and comments
EE Shopping Cart and ecommerce solution (coming soon)

 
Posted: 19 September 2009 02:47 PM   [ Ignore ]   [ # 8 ]   [ Rating: 0 ]
Joined: 2007-07-04
459 posts
Twobelowzero - 19 September 2009 09:34 AM

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”}

 
Posted: 21 September 2009 07:27 AM   [ Ignore ]   [ # 9 ]   [ Rating: 0 ]
Joined: 2009-05-22
5 posts
Joobs - 19 September 2009 06:47 PM

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

 
Posted: 21 September 2009 07:55 AM   [ Ignore ]   [ # 10 ]   [ Rating: 0 ]
Avatar
Joined: 2007-10-17
297 posts

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.

 Signature 

twobelowzero
EE add-ons support and comments
EE Shopping Cart and ecommerce solution (coming soon)

 
Posted: 21 September 2009 10:11 AM   [ Ignore ]   [ # 11 ]   [ Rating: 0 ]
Avatar
Joined: 2005-10-03
27 posts

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.

 Signature 

Andy Mathers
Senior Interactive Designer
Scheffey Integrated Marketing
phone: 717.569.8274 x34
350 New Holland Avenue
Lancaster, PA 17602
.(JavaScript must be enabled to view this email address)
http://www.scheffey.com

 
Posted: 21 September 2009 06:17 PM   [ Ignore ]   [ # 12 ]   [ Rating: 0 ]
Joined: 2007-07-04
459 posts

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.

 
Posted: 25 March 2010 02:02 PM   [ Ignore ]   [ # 13 ]   [ Rating: 0 ]
Joined: 2009-09-29
28 posts
Scheffey - 21 September 2009 02:11 PM

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!