First off, let me say that I'm very excited for this module. I'll do what I can to help provide you great feedback.

I patched my .htaccess file

  # AIS: Adaptive Image Style
  RewriteCond %{REQUEST_URI} ^(.+)/files/styles/adaptive/(.+)$
  RewriteCond %{HTTP_COOKIE} ais=(.+)
  RewriteRule ^(.+)/files/styles/adaptive/(.+)$ /$1/files/styles/%1/$2 [R=302,L]  

Then I switched an image's display over to "adaptive". The result is an image that is never generated.

ex source

http://localhost/sites/default/files/styles/threshold-992/public/229065_210942208939707_108653182501944_672981_2308527_n.jpg

When investigating for the file on my computer I find that the "threshold-992" folder is also never created. No error is thrown, the image just doesn't show up (screenshot).

When I visit the "adaptive" image style "admin/config/media/image-styles/edit/adaptive" I also see no image generated (screenshot).

img markup

<img width="800" height="600" style="width: 160px; height: 120px;" typeof="foaf:Image" src="http://localhost/playground2/sites/default/files/styles/adaptive/public/modules/image/sample.png?cache_bypass=1323833666" alt="Sample modified image" title="">

The good news is that when I click on the "view actual size" link I am redirected to...
http://localhost/sites/default/files/styles/threshold-992/public/modules...

and if I re-size my browser window smaller, I am redirected to...
http://localhost/sites/default/files/styles/threshold-768/public/modules...

and smaller yet still...
http://localhost/sites/default/files/styles/threshold-480/public/modules...

So the redirect works, it's just that the images are not being generated.

Let me know if there is anything I can do to help troubleshoot this.

Comments

spotzero’s picture

Hey animelion,

Do the built-in Drupal 7 image styles generate the sample pictures correctly (Example: /admin/config/media/image-styles/edit/thumbnail)? Also, do the sample pictures for the included 'threshold-x" styles work?

I can confirm that on the "admin/config/media/image-styles/edit/adaptive" the sample images don't work. The rewrite rule kicks in and forwards you away from the sample picture unfortunately. I'll fix this, but it's not preventing anything from working.

From your other issue, I see that you're using xampp, which I don't think comes with the GD2 or imagemagick libraries, which images styles requires. If that's what is causing problems, it should mention it on the status report page (/admin/reports/status).

Thanks for trying out the module,

spotzero.

bryancasler’s picture

Thanks for the feedback. I checked to see if I had GD2 or imagemagick libraries on "/admin/reports/status" and this is what it looked like (screenshot).

This is weird because it's telling me "Couldn't find the AIS htaccess rules in the htaccess file. Without these rules, AIS will not work." However that's clearly not the case (screenshot).

I also checked my xampp install's phpinfo to see if it had GD support and it does look like I do have it (screenshot).

spotzero’s picture

The code looking for the AIS lines in the .htaccess looks for a very specific string, so it's possible to have something equivalent, but that doesn't get matched correctly. If those are you're only changes to the .htaccess file, can you attach it?

Do the sample images work for other image styles?

bryancasler’s picture

Here is my htaccess file (.htaccess). I'm using Drupal 7.10

All of the sample images work except for the "adaptive" style.

spotzero’s picture

Thanks again for the quick feedback.

So:
- Image styles are working
- The JavaScript is correctly selecting a style
- The rewrite rule is rewriting based on the style selected by the JavaScript

So, we need to check that the URLs that are being rewritten (original and rewritten) are both indeed valid.

First, check to make sure the "adaptive" image style url is correct.
Do this by commenting out (or removing) the AIS changes to your htaccess file, then trying to view the images with the display set to 'adaptive' again. The adaptive image style should just show you your original picture. The URL for the image should look something like this: "http://localhost/sites/default/files/styles/adaptive/public/image_name.png".

If the image doesn't work here, then the problem with the way Media's generating the image url, and we'll look into that.

If that works, put the AIS changes back into the .htaccess, go back to the content and get the generated HTML for the image in the content when the display is set to a working value (like 'Large') and the generated HTML for the image when the display is set to 'adaptive', for comparisons.

Also, try and go to the 'adaptive' image url, and copy the url that you're taken to.

If the image doesn't work there, then there the problem is with what url is being rewritten to. From there we'll figure what correct url is supposed to be to display the image style, and fix up the rewrite rule.

bryancasler’s picture

Ok, here is what I did...

Removed AIS changes from htaccess
Viewed an image with the "adaptive" display style. The original image correctly displays.
ex src: http://localhost/playground2/sites/default/files/styles/adaptive/public/ssc2006-02b1.jpg

Added back in the AIS htaccess changes
Viewed an image with the "adaptive" display style. The adaptive image does not display.
ex src: http://localhost/sites/default/files/styles/adaptive/public/ssc2006-02b1.jpg

Viewed an image with the "large" display style. The large image correctly displays.
ex src: http://localhost/playground2/sites/default/files/styles/large/public/ssc2006-02b1.jpg

Looks like the adaptive image style is completely missing my installations sub-folder "playground2". I'm going to guess this is the culprit. Hope this info helps. Thanks for responding to me on this, I am really excited to start implementing adaptive layouts finally.

spotzero’s picture

Awesome, thanks.

Well good news, I can reproduce the problem. It is an issue with the rewrite rule, and I'm working on a fix. For now, looks like things will only work if Drupal is at the root of the webserver.

spotzero’s picture

Actually, I'm sorry animelion, here's a real solution:

Change:
RewriteRule ^(.+)/files/styles/adaptive/(.+)$ /$1/files/styles/%1/$2 [R=302,L]
To:
RewriteRule ^(.+)/files/styles/adaptive/(.+)$ /playground2/$1/files/styles/%1/$2 [R=302,L]

I'm still looking for a more general solution, but from what I'm reading, it might not be possible. Worst come to worst, you can make it work by hard coding Drupal's path into the RewriteRule. If I can't find a more general rewrite rule to do automatically, I might have to include this as part of the install instructions.

Thanks for all your help.

spotzero’s picture

Title: Does not work » Images are rewritten to the wrong URL
Status: Active » Needs review

Here's the solution. The RewriteBase directive must be set correctly.

If Drupal's located at the root (www.example.com/) the rules should be:

  RewriteBase /
  RewriteCond %{REQUEST_URI} ^(.+)/files/styles/adaptive/(.+)$
  RewriteCond %{HTTP_COOKIE} ais=(.+)
  RewriteRule ^(.+)/files/styles/adaptive/(.+)$ $1/files/styles/%1/$2 [R=302,L]

In your case, the rewrite rules should read:

  RewriteBase /playground2
  RewriteCond %{REQUEST_URI} ^(.+)/files/styles/adaptive/(.+)$
  RewriteCond %{HTTP_COOKIE} ais=(.+)
  RewriteRule ^(.+)/files/styles/adaptive/(.+)$ $1/files/styles/%1/$2 [R=302,L]

I'll update the documentation and code to reflect this requirement.

bryancasler’s picture

Thanks a million spotzero. I haven't got it working yet but I'm going to keep trying. I'll report back anything I'm able to figure out.

BIT’s picture

  • I have the same problems with this and I did edit the htaccess exactly like you.
  • Checked the file system...no images in the ais image style folders like the other unrelated styles
  • Checked with other image style...everything works
  • Checked if the htaccess responds to my changes and it does but it does not recognize your rules
  • Status Report : Notice: Undefined index: value in theme_status_report() (line 204 ...
    Adaptive Image Styles
    Couldn't find the AIS htaccess rules in the htaccess file. Without these rules, AIS will not work.

The only new question here is if a shared hosting can be causing the problems

spotzero’s picture

Rewrite rules are a tricky thing. I'm working on rephrasing them to be more straight forward and rewriting the report status warning to give more useful debug messages and offer guidance on the correct way to configure them.

BIT: Can you give me:
1. The URL you're using to get to Drupal.
2. The Rewrite rules you've added to Drupal's .htaccess file.

My latest revision of the Rewrite rule look like this:

# AIS: Adaptive Image Style
RewriteBase /
RewriteCond %{REQUEST_URI} ^(.+)/files/styles/adaptive/(.+)$
RewriteCond %{REQUEST_URI} !/modules/image/sample.png
RewriteCond %{HTTP_COOKIE} ais=(.+)
RewriteRule ^(.+)/files/styles/adaptive/(.+)$ $1/files/styles/%1/$2 [R=302,L]

But remember, the RewriteBase needs to be correctly set.

edit
This rewrite rules above are wrong, they should be:

  RewriteBase /
  RewriteCond %{REQUEST_URI} ^(.+)/files/styles/adaptive/(.+)$
  RewriteCond %{REQUEST_URI} !/modules/image/sample.png
  RewriteCond %{HTTP_COOKIE} ais=([a-z0-9-_]+)
  RewriteRule ^(.+)/files/styles/adaptive/(.+)$ $1/files/styles/%1/$2 [R=302,L]
BIT’s picture

Well I just use the root for example http://mykonosecret.com and I did install Drupal in the root of that domain but it is installed on a shared hosting if that has any relativity or not ,I might try to use ais on another website that has it's own server but could it be that causing the problem ...?
This is my ais rule:
# AIS: Adaptive Image Style
RewriteBase /
RewriteCond %{REQUEST_URI} ^(.+)/files/styles/adaptive/(.+)$
RewriteCond %{REQUEST_URI} !/modules/image/sample.png
RewriteCond %{HTTP_COOKIE} ais=(.+)
RewriteRule ^(.+)/files/styles/adaptive/(.+)$ $1/files/styles/%1/$2 [R=302,L]

RewriteBase is correctly set I think because I used the root of this domain for my Drupal installation. What can I say maybe it is the Shared hosting ,maybe there is a trick I need to do on my primary domain of this shared hosting ,maybe I am just a noob :(

spotzero’s picture

Found the bug in the rewrite rule:

RewriteCond %{HTTP_COOKIE} ais=(.+)

Should be:
RewriteCond %{HTTP_COOKIE} ais=([a-z0-9-_]+)

This is an old bug, apparently I've got to go over all of my documentation and make sure its consistent.

BIT’s picture

Status: Needs review » Fixed

Thank You spotzero and sorry for missing that ;)

BIT’s picture

Got it working but still getting the error messages displayed:
Notice: Undefined index: class in ais_preprocess_image() (line 204...modules/ais/ais.module).
Notice: Undefined index: value in theme_status_report() (line 2552...system/system.admin.inc).
And on the status report there is still a message: "I do not see the rules" but IT WORKS AND I LOVE IT

spotzero’s picture

Awesome BIT, I'm glad to hear its working for you.

Notice: Undefined index: class in ais_preprocess_image() (line 204...modules/ais/ais.module)

I've fixed this in the dev version.

Notice: Undefined index: value in theme_status_report() (line 2552...system/system.admin.inc).

I'm not able to reproduce this one and I'm not sure if its caused by the AIS module (it doesn't do much with of the theme other than adding a class to any adaptive images). If you disable the AIS module, do you still see this notice? If they go away, that will point to AIS being the cause and we'll dive in deeper.

And on the status report there is still a message: "I do not see the rules"

The requirements check in AIS module 1.0 looks for a very specific string in the htaccess file, since you're rocking the latest version of rewrite rules, it doesn't find it and you fail the requirements check. Since AIS is working, you can safely ignore this message. I'm working on better rewrite rule checking algorithm so these warnings should either clear up in the next major release, or become more helpful.

Cheers.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

robertor’s picture

Hi there.

I am encountering the same issue as you guys, where only the Original image is being shown.
I have followed the steps above, but everything looks correct.

The URL of the original image that is shown is:
http://localhost/jb/sites/default/files/images/styles/adaptive/public/1....

I can confirm that the correct images have been generated and look correct, by looking in:
http://localhost/jb/sites/default/files/images/styles/threshold-1200/pub...

There are no JS errors on page load. I am displaying the image in a view using the Adaptive Image Style.

The site is running locally in a sub folder. I can confirm .htaccess is being parsed as if I change the RewriteBase to / then the site fails to load at all. This is my rewrite:

# AIS: Adaptive Image Style
  RewriteBase /jb
  RewriteCond %{REQUEST_URI} ^(.+)/files/styles/adaptive/(.+)$
  RewriteCond %{REQUEST_URI} !/modules/image/sample.png
  RewriteCond %{HTTP_COOKIE} ais=([a-z0-9-_]+)
  RewriteRule ^(.+)/files/styles/adaptive/(.+)$ $1/files/styles/%1/$2 [R=302,L]

The section in status report all looks good:
Status Report Screenshot

Also, the cookie is being set to the correct threshold:
Cookie Screenshot

Here is a list of the files that have been generated, all looks good:
Files Screenshot

What is the next thing to check?

Thank You
Rob

robertor’s picture

Fixed it, just in case anybody else comes across this issue, in Drupal 7, if you specifiy a different directory for an Image to be uploaded to, you need to specify this in the rewrite.

For example, I set my uploaded images to go into sites/default/files/images therefore had to make the change to the rewrite to account for this:

# AIS: Adaptive Image Style
RewriteBase /jb
RewriteCond %{REQUEST_URI} ^(.+)/files/images/styles/adaptive/(.+)$
RewriteCond %{REQUEST_URI} !/modules/image/sample.png
RewriteCond %{HTTP_COOKIE} ais=([a-z0-9-_]+)
RewriteRule ^(.+)/files/images/styles/adaptive/(.+)$ $1/files/images/styles/%1/$2 [R=302,L]

bdanin’s picture

I was having a similar issue. I'm pretty sure that the re-write update from comment #20 fixed the issue. Now I just need to remember that I cannot have my images in sub-directories of files/images (thanks for the fix robertor) ... is there a fix for that? It would be nice to be able to put images in logically defined sub-directories for long-term organization, especially on sites with many images.

mr.marlin’s picture

#12 worked for me. Thanks!!

9802008’s picture

Rewrite of subdomain URL not working correctly.

The Image url should be:
http://new.mongena.co.za.dedi779.jnb1.host-h.net/sites/default/files/sty...

However it is rewritten with an incomplete domain name:

http://new.mongena.co.za/sites/default/files/styles/threshold-992/public...

I have the following in the .htaccess file:

  RewriteBase /
  RewriteCond %{REQUEST_URI} ^(.+)/files/styles/adaptive/(.+)$
  RewriteCond %{REQUEST_URI} !/modules/image/sample.png
  RewriteCond %{HTTP_COOKIE} ais=([a-z0-9_-]+)
  RewriteRule ^(.+)/files/styles/adaptive/(.+)$ $1/files/styles/%1/$2 [R=302,L]

Have tried setting $base_url in settings.php with no luck:


$base_url = 'http://new.mongena.co.za.dedi779.jnb1.host-h.net';
9802008’s picture

Temporary solution to #23 - hard code subdomain in .htaccess, e.g.;

RewriteRule ^(.+)/files/styles/adaptive/(.+)$ http://new.mongena.co.za.dedi779.jnb1.host-h.net/sites/default/files/styles/%1/$2 [R=302,L]

Any ideas for the correct RewriteRule?

vacho’s picture

This is working for me

RewriteBase /
RewriteCond %{REQUEST_URI} ^(.+)/files/styles/adaptive/(.+)$
RewriteCond %{REQUEST_URI} !/modules/image/sample.png
RewriteCond %{HTTP_COOKIE} ais=([a-z0-9-_]+)
RewriteRule ^(.+)/files/styles/adaptive/(.+)$ $1/files/styles/%1/$2 [R=302,L]