I have installed Drupal 4.7 and Gallery 2.1. Everything is working very nice, gallery url_rewrite also.
In same installation of Drupal I am using Lightbox2 which is very nice working with image.module, but doesn't work with gallery2.

- I checked up in setting of Lightbox2: Enable Gallery 2 Filter
- I activated G2 filter and Lightbox filter

I found that G2 Filter itself generate only picture, not picture which is link.
Here is what G2 Filter generate me:

<div class="giImageBlock nowrap">
	<div class="one-image">
		<div><a href="/drupal/view/SNS/CRW_8975b.jpg.html"></a></div>

		<div><img
		src="/drupal/galleries/download/CRW_8975b.jpg?g2_itemId=47&amp;g2_serialNumber=1&amp;g2_GALLERYSID=f78cb7038f3624228dde39336b68485c"
		width="220" height="147" class="giThumbnail" alt="CRW_8975b" longdesc=""
		/></div>
	</div>
</div>

Does somebody knowns, if it is possible to use Gallery2 module for inline pictures in articles which will show full size after click on them with help of Lightbox2.
Image module works like this, but I will prefer to use Gallery2, because main gallery on site will be using it anyway.

Thank you for help.

Comments

gumnaam1’s picture

I too had lots of problems integrating G2 filter and lightbox v2.
but finally I got it done. Here are my findings, hopefully they will help you.

1) First try and get G2 filter to work, without lightbox. (i.e. disable lightbox module).

2) Make sure you do the basics right. e.g. enable G2 filter in the gallery module settings.
Also if you want thumbnails bigger that what gallery normally shows, e.g. on my gallery
my thumbnails are 150px, but in any article that I write, they are about 300px ,
If you want this then , you will need to select 'full size' option, in the g2 filter settings of gallery module.

Also make sure you enabled G2 filter in your input method.

3) Another thing to note, in G2 filter, is that it only accepts itemIDs of the original file. e.g. if you have a
800x600 file, and your default image size in gallery2 is 640x480, the 800x600 image will have a different
itemID than the scaled down 640x480 ver. So make sure you pass the original size photo's itemID.
Also itemIDs for watermarked images is different and will not work.
in short itemIDs for resized images or watermarked images will not work, only itemID of original images will work.

Now for lightbox module.
1) To use lightbox module with gallery2. make sure lightbox filter has a heavier weight than G2 filter.
So the text is converted to an image link by g2 filter first and then lightbox module can add
'rel="lightbox"' later.
(You can do this in the rearrage tab of the input methods configuration menu).

2) If you see the lightbox filter code, it replaces target='' attribute inside the link.
This is a problem, as by default , the G2 filter will not add the target attribute, and hence lightbox filter has
nothing to replace.
You can specify a target in the G2 filter settings, but then the link will have target='_blank' , but lightbox
filter expects target='' . So you have to change that to a regular expression target='.*'
inside the lightbox filter code and also add a target value in the G2 filter settings..

Let me know if you need more details, I got this working last week, so I am still fresh with the workarounds.

http://www.bhaskarvk.info

diegogers’s picture

I had the same problem you did. I followed your instructions and made the two filters work together.

But... as the G2 filter makes the link to the image page and not directly to the image, lightbox doesn't work.

Is there a way to make this work? Thanks

gumnaam1’s picture

ah yes,
I remember running in to the same problem.
So I hacked the lightbox module.
Remeber the code below is an ugly hack, and will not work if you disable lightbox module.
ideally it should go in gallery2 module, but I am not a PHP developer, so I choose the easiest way.

Put this inside lightbox2.module, file in the modules/lightbox2 directory.
Replace every thing between

case 'process':
..
return $text;

with

$text = ' ' . $text . ' ';
    preg_match('/g2_itemId=(\d*)/',$text,$matches);

    // the below 2 lines should be all on one line.
    $text = preg_replace('/a href=".*"/','a rel="lightbox" href="/gallery2/main.php?g2_view=core.DownloadItem&amp;g2_itemId='.$matches[1].'&amp;g2_serialNumber=1"',$text);


    $text = substr($text, 1, -1);

So your final code should look something like

case 'process':
    $matches = array();
        $text = ' ' . $text . ' ';
    preg_match('/g2_itemId=(\d*)/',$text,$matches);
        $text = preg_replace('/ShowItem/','DownloadItem',$text);
        $text = preg_replace('/a href=".*"/','a rel="lightbox" href="/gallery2/main.php?g2_view=core.DownloadItem&amp;g2_itemId='.$matches[1].'&amp;g2_serialNumber=1"',$text);
        $text = substr($text, 1, -1);
    return $text;

Important :- Remember to enable 'Full Size' option in the gallery2 filter settings, otherwise this will not work.

In case you are wondering, what I am doing is , replacing the link to html page, that g2 filter creates, with link to
the actual image. I pick the itemID to the actual image from the link to the page, using reg-ex.
Since the itemID is picked from the html link, it is required, that 'Full Size' option be enabled.

Also I assume your original gallery2 (not the gallery2 module) is installed at /gallery2/ , and you have URL rewriting turned on.

All the best, do let me know if it worked out for you,

http://www.bhaskarvk.info

flohthegecko’s picture

Sorry to bother, and first of all thanks for the hack
gumnaam1

You saved at least my hope in this combination: Drupal 4.7.2, G2 and Lightbox2
Ok, it works, BUT
does any one have an idea how to extend this hack not only to take "$matches[1]",

The reason why I'm asking is simple:
I would like to put several thumbnails in the text
and with the Hack like this, the lightbox shows allways the same picture in the Overlay..

Additional Question:
There should also be a possibility to get the album from the G2 Filter and put it as parameter
behind the "rel=lightbox" so you can browse through the pictures in LightboxV2

An really best support wold be also to fill the "title=" parameter that is supportet by
lightbox to get some text under the pictures in lightbox, probably possible to pass the
gallery description, filename or comments there..

http://www.geckos-pla.net

randomangles’s picture

Instead of this line in gumnaam's code:

// the below 2 lines should be all on one line.
    $text = preg_replace('/a href=".*"/','a rel="lightbox" href="/gallery2/main.php?g2_view=core.DownloadItem&amp;g2_itemId='.$matches[1].'&amp;g2_serialNumber=1"',$text);

Use this to make the hack work with more than one image on a page.

// the below 2 lines should be all on one line.
    $text = preg_replace('/a href=".*g2_itemId=([0-9]+)"/','a rel="lightbox" href="/gallery2/main.php?g2_view=core.DownloadItem&amp;g2_itemId=$1&amp;g2_serialNumber=1"',$text);

I've modified the regular expression so that it looks for a g2_itemId value in the href attribute, and uses that value in the string that replaces the original link. If you look carefully you'll see it says "g2_itemId=$1" in the second half of the preg_replace code. That $1 is the itemId that was found in the first half.

There are probably better ways of doing this, but this will work for me until I have time to do something better.

EastwoodArts’s picture

I just can't seem to get the lightbox module to do its job. I have all working and tried some variations on the replace code. Maybe im not understand what settings need to be in the gallery2 'URL Rewrite' setting. I have the module activated but none of the rules activated... I have tried so many different variations. But if anyone has a suggestion I would appreciate it.
Is the g2image thing an important part? Also i have the 'input formats' arranged for lightbox to be a higher number than gallery2.

ricobilly20’s picture

thanks for your great explanation, but i cant really find the G2 modul, do you mind if you can kindly provide me the url,

thanks