I'd like to improve the blocks that image.module provides. There's several image-based block submitted on the blocks snippets page, and based on those I'd like to add the following features:

- choose how many images to show in the block
- choose which gallery the images come from, or all images
- if the images are from a gallery, whether to show a 'Gallery' link (same as the 'More' link that Views can put in blocks)

However, I'm not sure whether this can be done in image.module without adding a dependency on image_gallery -- I don't really know much about module dependencies.
Would it be better providing these blocks in image_gallery.module?

Comments

drewish’s picture

you could just add blocks to the image_gallery module... though my personal preference at this point is to add enough views support to do it and then ship default views to define the blocks.

joachim’s picture

Hmm... using views would be sensible and logical.
But then that raises the question that galleries themselves should be views. Because after all, if the "N recent images" block is provided by a view, then we might as well use the view's built-in "More" link to go to the page that the view provides.
Which raises the secondary question that taxonomy should be views.
...
which is getting into very deep water.

How much extra views support would be needed, anyway?

drewish’s picture

i'm all for moving gallery into a views plug-in. i'd talked to walkah about that, he didn't seem to mind.

joachim’s picture

Status: Active » Needs review
StatusFileSize
new3.63 KB

Here's a patch on HEAD that adds more views support:

- Image gallery view type
- reimplements both Random Image and Latest Image as view blocks
- Latest Images view provides a page too.

drewish’s picture

what do you think about adding a default view to replace the /image menu handler? if views is enabled we disable /image?

joachim’s picture

That would be the ideal, but there's the matter of listing sub-galleries at the top of image lists.
It boils down to listing sub-terms at the top of a taxonomy list, but I don't know how to do it. I'd appreciate hints! :)

joachim’s picture

StatusFileSize
new8.05 KB

Couple of problems with that patch I now realize: I left 'bonus_grid' in from the module I was copying from; and the views_default.inc wasn't in because it's a new file.

Let's try again...

joachim’s picture

I've found a way to do the child galleries, but it's not hugely pretty.

Basically, I've copied chunks from both image_gallery_page() and theme_image_gallery() into theme_image_gallery_view(). This is probably less than brilliant because it's mixing data and theming.
Showing the basic image/ page with a summary of galleries is proving less than trivial too.

On the plus side, this could give the admin more control over what is displayed: I could create a number of 'dummy' fields called things like "Image gallery: child gallery name", "--count", "--latest", and so on, and adding those to a view would determine how much info about the child gallery is shown.

Given the unprettiness, I don't know if it's worth doing -- what do you think?

gracearoha’s picture

This sounds like a very useful feature that i would surely be interested in using - of course i'm all for something "pretty" if it can be pulled off. Sorry, i'm hopeless in the coding area, but am happy to do testing.

joachim’s picture

I've figured out a non-ugly way of doing it -- generate the gallery pages ourselves, as we currently do, and create the child gallery list ourselves too. Then embed the gallery view (http://drupal.org/node/48816) if the views module is present.
I've got it working, just got stuff to tweak now :)
If you could test a patch when it comes, that would be great, gracearoha.

joachim’s picture

Version: 5.x-1.0 » 6.x-1.x-dev
StatusFileSize
new14.62 KB

Here's a patch on HEAD.

This reimplements all blocks and galleries as Views. If the Views module isn't present, you get the old functionality.

There are three default views provided:
- recent images: a block showing one image, and a page showing all latest images
- random image: just a block
- image gallery: takes a taxonomy argument to show a gallery.

Overriding these built-in views will give the site admin tons of control, eg random image from gallery X (add a filter), show creation time in galleries (add a field), order by anything you like (add sort criteria), etc.

These are all implemented with a Views Style Plugin for image galleries. You can use this in custom views to make any sort of collection of images.

The code in theme_image_gallery() is not hugely pretty, as it has to juggle about depending on whether there is Views support or not. But the only alternative would be split the theming functions in that module (in particular, theme_image_gallery which themes both child galleries and the gallery itself -- that has to be fed an empty list of images if we're using Views). AFAIK this would be a no-no as it could break people's theming overrides.
Making the child gallery list ourselves is a bit of a halfway house -- Views 2 in Drupal 6 should allow us to make that as a view too.

As the patch currently stands, the new views stuff in image.module adds a dependency on the stylesheet in image_gallery.module.
This isn't ideal. I'd recommend moving image_gallery.css up into image too, but I can't do that in a patch. (I don't see any other way to get round that if we want Recent images and Random image in the main module.)

I wasn't sure which module to put the image_gallery built-in view into... but after ten minutes trying to justify it in image.module, I've moved it to image_gallery. ;)

joachim’s picture

(DELETE: duplicate comment)

joachim’s picture

Testing...?
Sorry for spam, but Drupal has just eaten my comment & patch twice.
Is this working?

EDIT: apparently it is.... eventually :/

zach harkey’s picture

Subscribing

Can't test now, but this is EXACTLY what I've been asking santa for. Will test tonight.

gracearoha’s picture

Okay, perhaps i'm not such a great help.
I just tried to apply the latest patch - image_views_3 to what looks like the latest release of Image (5x-2x-dev - Nov 19)

But i received the following message:

(Stripping trailing CRs from patch.)
patching file image.module
Hunk #1 FAILED at 11.
Hunk #2 succeeded at 391 (offset -82 lines).
1 out of 2 hunks FAILED -- saving rejects to file image.module.rej
(Stripping trailing CRs from patch.)
can't find file to patch at input line 43
Perhaps you should have used the -p or --strip option?
The text leading up to this was:
--------------------------
|Index: views.inc
|===================================================================
|RCS file: /cvs/drupal-contrib/contributions/modules/image/views.inc,v
|retrieving revision 1.4
|diff -u -r1.4 views.inc
|--- views.inc 27 Aug 2007 22:50:39 -0000 1.4
|+++ views.inc 1 Dec 2007 15:03:06 -0000

It looks like a much more complex patch than i've used before. perhaps i need to do it in parts or something?
i simply put the patch in the image directory and used the command: patch < image_views_3.patch

joachim’s picture

Thanks for having a go :)
You need to apply it to CVS HEAD.

gracearoha’s picture

okay. me thinks the CVS HEAD thing is a bit over my head for now. I'll wait for the official release of the patch.
thanks so much for all your hard work.

joachim’s picture

It's actually pretty simple -- easier than applying a patch, IMO! You probably want to set up another installation of Drupal so you don't interfere with your current one. TortoiseCVS on Windows is pretty easy to use: http://drupal.org/node/22293

drewish’s picture

joachim, it looks like there's some kind of line ending conversion problem with contrib/image_gallery/views_defaults.inc

joachim’s picture

Yes, I saw the new files in the patch had extra line endings.
It's probably because I'm on Windows.
Any chance you can convert it at your end?

joachim’s picture

Title: Better image blocks: number of images, gallery choice » Using Views for image blocks and galleries
StatusFileSize
new13.85 KB

Ok... try this: I've removed the double endings in the new files, and converted the whole thing to unix line endings for good measure.

Oh, and let's update the issue title while I'm at it :)

Hetta’s picture

Anybody know the performance hit of views vs. image-internal gallery?
Because I'm on a shared server, and I'm told my (very stripped-down) drupal install consistently hogs about 25 % of the CPU ...
If views actually helps that, I'll install it and give this patch a shot.

Thanks!

summit’s picture

subscribing.
greetings,
Martijn

drewish’s picture

Version: 6.x-1.x-dev » 5.x-2.x-dev
Status: Needs review » Active

this should be done against the 2.x branch since i swore up and down that i wouldn't add any more features to the 1.x branch.

cleaned up some formatting in the .css file.

fixed a couple of coding standards things identified by the coder module.

in theme_image_gallery_view() removed debugging code and changed it to always return $content since it's always going to be defined and returned.

i'm going to go ahead and commit this. there are some issues but it's a big enough improvement that they can be addressed later on.

drewish’s picture

Also, i'd like to use this as a starting point for the Drupal 6 code. I'd really like to rip out all the image_gallery stuff from that and do it all via views.

underpressure’s picture

Will the random block allow you to specify the number of images to display in the block?

I'm currently using a snippet and would love something to use something official instead.

I tried creating a a block with three random images but all I get is 3 random images that are all the same.

heres my url: http://www.ravalonline.com

drewish’s picture

underpressure, i think you could adjust the random image view to select more than one image.

joachim’s picture

underpressure: yup, just override the random image view and change the number of nodes per block.

For the various people who wanted other ways to sort galleries (by nid, creation date, etc) or change what's shown in galleries (hide node title, etc), all you need to do is override the 'image_gallery' view.

joachim’s picture

Documentation on creating and customizing galleries: http://drupal.org/node/207216

drewish’s picture

joachim: take a look at http://drupal.org/node/207198 we probably need some code in the image_gallery default view to select the correct taxonomy... and make sure it's been created.

underpressure’s picture

about the images blocks, is there any chance of being able to select (by option) photos that are landscape or portrait only? when creating image blocks in views?

joachim’s picture

underpressure: you could add all sorts of filters or sorts via views, but as far as I can tell, there's no data about individual image sizes in the database, just the derivatives.

drewish’s picture

if the height and width are stored in the database you could add a WHERE clause that compared them and only returned images where one was greater than the other...

jfall’s picture

Sorry to butt in, but I've been searching and trying various ways to do this for a week, (e.g., combining http://drupal.org/node/179998 with http://drupal.org/node/42597, among many other various attempts!) but this update to Image Gallery seems like exactly what I've been looking for.
If I understand correctly, this change will allow me to create a "gallery", which is really just a view of a taxonomy term, from any taxonomy?
E.g., so, as opposed to the single vocab. "Image Gallery", I could have a vocab. "subject" with terms like "wildlife", "people", etc. and another vocab. "techniques" with terms like "solar lens", "telephoto", etc. and create galleries from either or both of them? I could create a custom view on "User ID is Author" to create "per-user" galleries too?

OK - as I said, I already do this with custom summary views, but it was a trick to find out how and the "summary" views that list the galleries suck (see below). In my search, I came across a lot of people who will no doubt be thrilled to have a packaged solution, customizable through Views - myself included. So mostly, I just wanted to say - good on you - looking forward to seeing the result

I'm working with Image nodes and the Image gallery (have yet to see how all the CCK image_field solutions help in 5.x) Here are my basic requirements :

  1. each Image node a user creates goes into their personal "gallery"
  2. users can tag images from several taxonomies, including a free tagging vocab.
  3. in addition to the "per user" gallery, there is a gallery for each taxonomy to show all images tagged with a given term.
  4. there are "summary" pages for the "per-user" galleries and each taxonomy.
    ** All this I can do with current Image module + a few custom summary views **
  5. "summary" pages that are nicely formatted, with a description from the the taxonomy term and a sample photo from each gallery (just like the /image page in the Image module! By contrast - the custom summary view merely lists the taxonomy terms (blah) and appears to require a fair bit of custom theming to create a nice look. )
    ** This is the place I am currently stuck. I've been plugging away at creating a custom theme_views_summary_TAXONOMY function, but I'm brand new to PHP and Drupal, so finding it beyond me at present. **
  6. gallery should be viewable with an image browser, like Lightbox or Thickbox.
  7. cross taxonomy galleries would be nice. E.g., all wildlife photos using telephoto technique.
    ** Also easy with a custom view - but no way to create a summary of all such galleries, hmmm. **

I certainly don't mean these as "suggestions" - I sure you are at capacity with your own ideas - but could you let me know which of these use-cases your updated Image Gallery module will handle?

I'm new to Drupal, and apologize for not being able to offer much help, but will be happy to give 2.x a thorough test once it is ready. Thank you Thank you.
...Joseph

joachim’s picture

The summary pages are still made within the image gallery module, not with views. They're in fact inserted above each view, showing child galleries for the current gallery (ie child terms of the current term).
If theme_views_summary can be leveraged in some way to do this, that would be quite interesting. The problem I found was the the options for arguments are limited to the 6 or 7 that are built-in, but I didn't know about theme_views_summary. However, this will probably only work for the case when there are no arguments -- and the child gallery list is needed on every term, not just the no term case. But let us know what you find.

Lightbox or Thickbox -- I think I've seen forum posts on this, but have no idea myself.

jfall’s picture

thanks joachim...

after some hours of effort, I need to give up on trying to customize theme_views_summary. I'm pretty sure this is the right approach to moving those summary pages into Views too - then, I think, Image Gallery wouldn't really be needed anymore except as a wrapper to make things simple and provide a default if Views are not installed?!?

Anyhow, I'll keep watching for 5.x-2.x and give it a try -- again, thanks for your efforts on this, I think you're headed in a productive direction - I'll let you know how it turns out, but for now I need to fall back to using a single taxonomy - the one provided by Image Gallery.

...Joseph

Hetta’s picture

StatusFileSize
new13.04 KB

The random image block still needs some theming - I've included a screenshot of what it looks like now (the o is too much, and the spacing on portrait images, below the image itself, is much too much). I'd love to fix this myself, but couldn't find where to do this.

joachim’s picture

This is actually connected to this other bug you just closed ;)
http://drupal.org/node/190205

We have to take a conservative approach to the height set on the image LIs, so they can accommodate both the image (known height in px) and an unknown number of lines of text.
It can maybe be tweaked by setting a negative margin-bottom targetted at only that block.

Hetta’s picture

StatusFileSize
new132.52 KB
new118.21 KB

Ho hum. The views setup is fine, the old gallery setup has the empty space problem (screenshots attached) - which isn't all that bothersome, as it's in among a lot of other thumbnails.

Of course, the views-based gallery will have text floating on top of the images, if there's a lot of text ...

... you could count the number of characters in the title, and approximate from that, but that'd be just that - an approximation.

However, if the title is turned off, there should be no space at all left for it.

(I reopened the height issue, cos it got active again :-) )

Hetta’s picture

marked http://drupal.org/node/166344 as duplicate.

guillaumeduveau’s picture

Your work on this module is very cool Joachim, thanks, and thanks to all authors too :-)

One thing is, I don't have any taxonomy any more for my images ! If I edit an image associated with a gallery with a previous of the module, I don't have the taxonomy field any more. I can create a new image but not taxonomy either, same for import images. Give us back the taxonomy :-)

[edit] I found the solution. My vocab for galleries had been disactivated for the image content type. Leaving this above for prosperity...

One more thing, with pathauto I have this pattern in node path settings : [vocab-raw]/[termpath-raw]/[title-raw]. It works great.
In category path settings I have for my galleries vocabulary the pattern : [vocab-raw]/[catpath-raw]. However it always displays /image/tid/X. It would be so cool to have pathauto rewrite it too, to have a coherent URL system.

I don't understand views very well yet but I think I can do it with that. I added a view from the provided image_gallery view and set the URL page to /photos (that's the vocabulary name), and replaced in arguments taxonomy: term id by taxonomy: term name. Now I can access my gallery to /photos/name-of-the-gallery-term. There are still 2 problems. The first is that name-of-the-gallery-term can't have spaces or accents like é,à, ... Then I added an alias /photos for /image, but the links to the galleries are always /image/tid/X. Well I can hack this for the moment but would be cool to have a clean alternative.

Thanks again all for this very cool module !

joachim’s picture

guix, you should file a feature request for pathauto support. I have no experience at all of pathauto or token but maybe someone else will look at it :)

guillaumeduveau’s picture

Thanks. There's already this thread on pathauto suggesting image_gallery needs the token support but it hasn't been done so I've filled a feature request for token & pathauto support in image_gallery.

joachim’s picture

The height issue is now over at http://drupal.org/node/190205

What remains to be done on this issue before it can be closed?

joachim’s picture

Got to get this into 6, I suppose.
http://drupal.org/node/220295

jfall’s picture

Hi joachim -
just an update to your comment #35 above: http://drupal.org/node/134423#comment-705209

I have found a way to leverage theme_views_summary to display an exact replica of the Image.module's Gallery summary view. I'm now using CCK imagefield, but you're welcome to the code if its of any use (especially since it uses the css file and a method from the Image Gallery code nearly as-is!)...
http://lasqueti.ca/books/design-notes/image-gallery-summary-view

hope that is interesting for you - feel free to contact me if I can help.

sun’s picture

Status: Active » Closed (won't fix)

Sorry, 5.x won't get any new features.