scale down preview image on small screens

salamich

Joined: 2012-08-11
Posts: 7
Posted: Wed, 2012-08-15 09:14

Hi everyone

I'm using the widewind theme and I would like to switch to bigger image previews. Unfortunately this screws up the display on smaller screens with the menu overlapping the image etc. Is there an easy way to let the browser scale down the image if the width is too big?

Thanks a lot!

Login or register to post comments
tempg

Joined: 2005-12-17
Posts: 1633
Posted: Wed, 2012-08-15 14:19

It can be done, but EASY way? Probably not if you don't already know how to do it.
The only relatively easy way would be to define a set width, but that defeats the purpose and intent of the widewind theme.

Login or register to post comments
floridave
floridave's picture

Joined: 2003-12-22
Posts: 25949
Posted: Wed, 2012-08-15 14:35

I guess one could use jquery to get the browsers window size:
var viewportWidth = $(window).width();
var viewportHeight = $(window).height();
then I bet there is some other jquery method to scale the images if the browsers window is smaller.
I would use the theme chooser to detect mobile devices and deliver the mobile theme. perhaps it could be adapted to detect window size as well.
Will it be worth the effort for people with smaller screen resolutions? What size are we talking about?

Does this work:
http://www.ollicle.com/projects/jquery/imagefit/eg/

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

Login or register to post comments
salamich

Joined: 2012-08-11
Posts: 7
Posted: Wed, 2012-08-15 15:34

Thanks for your replies!

The main culprit is my iPad which, despite it's 2048x1536 resolution, still seems to render the pages at 1024px width. I'm already using the iMobile theme for regular browsing, but I still need to access the main page now and then.

I was hoping to avoid extensive JS hacks so I can easily maintain my modifications in the future. After playing around with the HTML output I found that the following comes pretty close to what I want:

Quote:
<img id="g-item-id-10" class="g-resize" src="xxx.jpg?m=xxx" alt="xxx" width="100%" style="max-width: 534px; max-height: 800px"/>

instead of the default output:

Quote:
<img id="g-item-id-10" class="g-resize" src="xxx.jpg?m=xxx" alt="xxx" width="534" height="800"/>

Is there a way to get my theme to output this code instead?

Login or register to post comments
tempg

Joined: 2005-12-17
Posts: 1633
Posted: Wed, 2012-08-15 17:28

The method @floridave is describing is likely a better option because it's theme-based.

The only other way is to change core files, which should be avoided if possible. I'm not sure that I remember which file, but if you're in the mood to tinker around, back up everything. Then look for modules > gallery > models. Copy the items.php file to your theme > models (you may have to create that folder, but I think it'll still work). Play away. Report back.

I haven't tested, but I can later this weekend if you haven't figured it out by then.

And, yes, changing this file could be a big deal, so be cautious.

EDIT: I'm actually thinking that copying the file won't work; you may have to actually replace the original file, which, of course, is more of a risk AND will be affected every time you update Gallery.

Login or register to post comments
floridave
floridave's picture

Joined: 2003-12-22
Posts: 25949
Posted: Wed, 2012-08-15 18:12

I'm not about to test much but this might be a solution:
add to the css:

.g-resize {
  max-width: 400px;
  max-height: 400px;
  width: expression(this.width > 400 ? "400px" : true);
  height: expression(this.height > 400 ? "400px" : true);
}

Adjust the 400s as you need.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

Login or register to post comments
salamich

Joined: 2012-08-11
Posts: 7
Posted: Wed, 2012-08-15 18:13

You're totally right. Modifying core files is not an option, so I had a closer look at jquery.imagefit.js floridave suggested and it really does exactly what I wanted. I only had to add the following code to the <head> of a local copy:

Quote:
<script type="text/javascript" src="http://www.ollicle.com/projects/jquery/imagefit/jquery.imagefit.js"></script>
<script type="text/javascript">
$(window).load(function(){
$('#g-photo').imagefit();
});
</script>

What's the proper way to add such modifications to my own theme?

Login or register to post comments
floridave
floridave's picture

Joined: 2003-12-22
Posts: 25949
Posted: Wed, 2012-08-15 19:09

That could be done in a theme or as a module. If you have a theme slightly modified already best bet is to create a copy of the theme and give it your name.
http://codex.gallery2.org/Gallery3:Themes#Duplicate_and_deploy_your_copy_of_the_default_theme

Quote:
<script type="text/javascript" src="http://www.ollicle.com/projects/jquery/imagefit/jquery.imagefit.js"></script>

you need to create a copy of that file and put in on your server. then use the path to it and not stealing the content/bandwidth from the other site.

Should not take much time to make that a module.

Dave

_____________________________________________
Blog & G2 || floridave - Gallery Team

Login or register to post comments
floridave
floridave's picture

Joined: 2003-12-22
Posts: 25949
Posted: Wed, 2012-08-15 19:29

Are we reinventing the wheel here?
Does this do waht you are after:
http://codex.gallery2.org/Gallery3:Modules:fittoscreen

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

Login or register to post comments
salamich

Joined: 2012-08-11
Posts: 7
Posted: Wed, 2012-08-15 19:44

Not exactly, this module resizes based on the entire page size minus a fixed pixel amount instead of using the picture's parent container. Unfortunately a static CSS doesn't seem work either as the browsers don't care about the aspect ratio so you end up with square pictures.

The jquery.imagefit.js script works perfectly though. Now I just have to find an elegant way to get my theme to output that code in the head :)

Login or register to post comments
floridave
floridave's picture

Joined: 2003-12-22
Posts: 25949
Posted: Wed, 2012-08-15 19:47

Ok here is a module:
please test and let me know

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

AttachmentSize
image_fit.zip2.13 KB
Login or register to post comments
salamich

Joined: 2012-08-11
Posts: 7
Posted: Wed, 2012-08-15 20:03

Awesome, this works like a charm! There's a just slight delay until the image is loaded and resized, but compared to the extensive modifications needed for individual "max-width" and "max-height" tags this seems like a perfect solution.

Thanks a lot for all your help!

Login or register to post comments
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 7887
Posted: Wed, 2012-08-15 20:36

in this example I simply edited photo.html.php and added inline style
<?= $item->resize_img(array("id" => "g-item-id-{$item->id}", "class" => "g-resize", "style" => "width:100%;max-width:{$item->resize_width}px;height:auto;")) ?>
no javascript involved.
although I had to restyle #g-content

<style>
    #g-content{
        -moz-box-sizing: border-box;
        -webkit-box-sizing: border-box;
        box-sizing: border-box;
        width:100%;
        margin-right: 260px;
        padding: 0 20px;
    }
</style>

-s
All New jQuery Minislideshow for G2/G3

Login or register to post comments
tempg

Joined: 2005-12-17
Posts: 1633
Posted: Wed, 2012-08-15 21:38

@suprsidr: That method gives two height and width declarations: one from the pre-existing code and one from the code you used. Does it matter if the two conflict? Will all browsers just honor whichever one comes last?

Login or register to post comments
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 7887
Posted: Wed, 2012-08-15 23:42

the style will be preferenced.
although crappy old unsupported IE would fail on max-size - force chrome frame on those few.
but we're talking modern and mobile here.

-s
All New jQuery Minislideshow for G2/G3

Login or register to post comments
salamich

Joined: 2012-08-11
Posts: 7
Posted: Thu, 2012-08-16 16:00

@suprsidr: Cool, thanks for sharing! Seems to work great.

Login or register to post comments
floridave
floridave's picture

Joined: 2003-12-22
Posts: 25949
Posted: Thu, 2012-08-16 20:56

Updated the wide wind theme with suprsidr changes. Cheers!

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

Login or register to post comments
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 7887
Posted: Sun, 2012-08-19 21:01

this would work across all modern browsers.
IE6/7 did not support max-width but who cares about those 2 people ;)

-s
All New jQuery Minislideshow for G2/G3

Login or register to post comments