Hello,

with drupal 8 and photoswipe 4.1.0, the aspect ratio of a photo in lightbox mode is choosen incorrect, when a change from portrait to landscape appears. In the node display, the aspect ratio is correct, but not in the lightbox version. See screenshots.

Tested with Chromium 49 (Version 49.0.2623.87 Ubuntu 14.04 (64-bit)) and ImageMagick plugin (Version: 8.x-1.0-alpha1+3-dev).

Best regards,
Tobias

Comments

tobias-hd created an issue. See original summary.

ParisLiakos’s picture

probably because the data-size attribute is wrong..can you paste the generated markup of the link+image?

tobias-hd’s picture

Looks like you are right, with the wrong data-size attribute:

<div class="field__item">
<a href="http://localhost/drupal/sites/default/files/2016-03/DSC_1515.JPG" class="photoswipe" data-size="1200x1793" data-overlay-title="F macht ein Photo"><img src="/drupal/sites/default/files/styles/medium/public/2016-03/DSC_1515.JPG?itok=CZ7aTwl2" width="147" height="220" alt="(F macht ein Photo)" title="F macht ein Photo" typeof="foaf:Image" class="image-style-medium" />
</a>
</div>

PS: Uploaded the corresponding image (DSC_1515.JPG).

tobias-hd’s picture

StatusFileSize
new660.63 KB
kay.beissert’s picture

Same problem here, but my portrait images get stretched to landscape-format. The data-size-attribute is filled with the wrong image-size-values. How can this behaviour be solved.

Thanks

kay.beissert’s picture

After some fiddling with the "photoswipe.theme.inc" it seems, the item has no width- and height-value. So I load the image-file from the $uri first to get the height- and with-value. With these values I can define the dimension-array. I got this code from elsewhere on the internet and hey, I'am no coder, so this could be done nicer ;)

From line 44

  // The image.factory service will check if our image is valid.
  $image_file = \Drupal::service('image.factory')->get($uri);
  if ($image_file->isValid()) {
    $image_width = $image_file->getWidth();
    $image_height = $image_file->getHeight();
  }
  else {
    $image_width = $image_height = NULL;
  }

  $dimensions = array();
  if (isset($item->width) && isset($item->height)) {
    $image['#width'] = $dimensions['width'] = $image_width;
    $image['#height'] = $dimensions['height'] = $image_height;
  }
adamwhite’s picture

StatusFileSize
new1.28 KB

I was seeing the same problems and the change suggested in #6 worked for me. Here's that modification as a patch:

iamdroid’s picture

#7 works for me. Thank you.

segovia94’s picture

This problem is likely due to the core bug https://www.drupal.org/node/2644468 that incorrectly saves the width and height data from the first of multiple image uploads for all subsequent photos. It doesn't happen if you upload one photo at a time, but if you upload several in one batch then the first images dimensions are used for all.

This patch to core fixed the root issue. https://www.drupal.org/node/2644468#comment-11625775

Anonymous’s picture

#7 works . Thanks.

Tom83’s picture

#7 works. Drupal 8.2.8 & Photoswipe 8.x-1.0-beta3

drupalfan2’s picture

#7 worked for me. Thank you.

drupalfan2’s picture

When will this patch be committed to beta4 version?

anybody’s picture

Status: Active » Needs work

Could you please retry the latest dev and re-roll the patch against it, if the issue is not fixed there yet?

Thanks!

tobias-hd’s picture

Thanks for working on this. Unfortunately I have no drupal installation running anymore to verify the fix, and for private reasons I currently don't have time to set one up again. Sorry!

anybody’s picture

Status: Needs work » Needs review

Okay, thanks tobias-hd. Perhaps one of the others here will have a look / test and reroll the patch if still required.

Status: Needs review » Needs work

The last submitted patch, 7: aspect_ratio_incorrect-2695191-7.patch, failed testing. View results

sashken2’s picture

Patch #7 works good with Photoswipe 8.x-1.0-beta4

Photoswipe 8.x-1.0-beta5 not working on my site.

anybody’s picture

Hi sashken2,

is beta5 not working at all on your site or not with the patch? The patch surely needs a reroll to apply.

sashken2’s picture

Hi Anybody,

beta5 not working at all on my site. After downgrade to beta4 all works good

anybody’s picture

Version: 8.x-1.0-beta2 » 8.x-1.x-dev

Could you please open a new issue for that and describe what doesn't work? Is the library included correctly (JS Console), do you set classes manually, ...

The patch from this issue should get a new reroll against dev.

iamdroid’s picture

StatusFileSize
new1.01 KB

Clean beta5 works and this bug also appear.
I rerolled #7 for beta5. And then bug left again.

anybody’s picture

Status: Needs work » Needs review
anybody’s picture

Hi and thank you very much.
Plese also correct the if condition:

if (isset($item->width) && isset($item->height)) {

This should check for !empty() image_width and image_height. Roll the patch against dev. I think we can commit it to dev then, if we get some more reviews for the latest patch.

Thank you.

iamdroid’s picture

StatusFileSize
new1.07 KB

Yeah, you right. I just rerolled patch and even don't check that condition is wrong.
Here is an updated patch.

anybody’s picture

Status: Needs review » Fixed

Pushed to dev. Please test. This will be part of the next stable release one day :)

  • Anybody committed aad8096 on 8.x-1.x
    Issue #2695191 by iamdroid, adamwhite, tobias-hd, Anybody: aspect ratio...
FO’s picture

Hi,
I've always the same bug with the last dev.

anybody’s picture

@FO: Did one of the patches / solutions posted above work for you? This is definitly in latest 8.x dev. You're using Drupal 8, right?

If you can find out the reason for the problems or write a test patch we can reopen this.

FO’s picture

Yes, I'm using Drupal 8.5.5 with the last dev of Photoswipe
In my composer.json file :

"drupal/photoswipe": "1.x-dev"

But I'm using blazy_photoswipe for my gallery :
http://abconcept.ch/fr/galerie

anybody’s picture

Status: Fixed » Needs work
anybody’s picture

I'm not going to work on this bug in the near future. If paid development is wanted, please contact me. Otherwise I'll review / commit patches from others. Thank you.

FO’s picture

Ok ! Thanks !

kingjimza’s picture

Hi Guys,

I had this issue as well and seem to have found a module that clears the "incorrect aspect ratio" issue.

I am running;

  • D8.6.1 (just updated to D8.6.2)
  • photoswipe; Version: 8.x-2.2
  • blazy_photoswipe; Version: 8.x-1.0-rc2

After two full days of trying to get this work, I read #9 and followed links.

At the very bottom; #94 there is a link to a module;
See; Image Field Repair

I installed and ran the module (admin/config/media/image_file_repair/dimensions), It all works now :)

Seems it was more of a Drupal core issue than a Photoswipe issue.

Cheers and let us know if this works for you.

anybody’s picture

Priority: Major » Normal

@FO & @kingjimza: Please retest the latest 8.x-2.x-dev after #3021740: Play nice with Blazy, Slick has been commited. 8.x-1.x will not be maintained by me anymore.

anybody’s picture

Status: Needs work » Fixed

Setting this fixed again.

anybody’s picture

Status: Fixed » Closed (fixed)