acrylian / zp_picturefill

A Zenphoto plugin for responsive images
GNU General Public License v3.0
0 stars 1 forks source link

width and height attributes #6

Closed acrylian closed 10 years ago

acrylian commented 10 years ago

The fallback <img> should have widht and height attributes. Possibly the <source> as well (not sure if they can or should have right now, have to look at the docs).

Bruno21 commented 10 years ago

My dirty hack for < img > Hope you'll have time to do better code ;-)

function getResponsiveImage () {
.../...
  //standard desktop size
  if (!is_null($standard_sd) && !is_null($standard_hd)) {
    $standard_source = html_encode(pathurlencode($standard_sd)) . ', ' . html_encode(pathurlencode($standard_hd)) . ' 2x';
    $size = ResponsiveImageDims($standard_sd, false);
  } else if (!is_null($standard_sd)) {
    $source_standard_sd = $standard_sd;
    $standard_source = html_encode(pathurlencode($standard_sd));
    $size = ResponsiveImageDims($standard_sd, false);
  } else if (!is_null($standard_hd)) {
    $standard_source = html_encode(pathurlencode($standard_hd)) . ' 2x';
    $size = ResponsiveImageDims($standard_hd, true);
  }
.../...
  $html .= '<img srcset="' . $standard_source . '" alt="' . $alt . '" height="' . $size['height'] . '" width="' . $size['width'] . '" >';
.../...
}

function ResponsiveImageDims($filename, $hd=false) {
    $imageinfo = NULL;
    $filename = PROTOCOL . "://" . $_SERVER['HTTP_HOST'] . $filename;
    $rslt = getimagesize($filename, $imageinfo);
    if (is_array($rslt)) {
        // retina (window.devicePixelRatio == 2)
        if ($hd) return array('width' => ($rslt[0] / 2), 'height' => ($rslt[1] / 2));
        // non-retina
        else return array('width' => $rslt[0], 'height' => $rslt[1]);
    } else {
        return false;
    }
}
acrylian commented 10 years ago

Thanks :-) It is indeed possible easier by passing the values from one of the image generating functions as we already have already have a proper function to get the new resized width/height values (in 1.4.6 of course).

acrylian commented 10 years ago

Please take a look and do some testing. I am sure I missed something ;) If you use any get function directly you need to update to the new arrays. Please see file comments.

Bruno21 commented 10 years ago

image.php:

Notice: Undefined index: img_sd in /Library/WebServer/Documents/zenphoto/plugins/zp_picturefill.php on line <i>516</i>
Notice: Undefined index: img_hd in /Library/WebServer/Documents/zenphoto/plugins/zp_picturefill.php on line <i>516</i>
Notice: Undefined variable: standard_source in /Library/WebServer/Documents/zenphoto/plugins/zp_picturefill.php on line <i>155</i>

print_r($img);

            Array
(
    [0] => Array
        (
            [img_sd] => Array
                (
                    [url] => /zenphoto/cache/test/2014-04-26_bol-dor-2014_6347_595_watermark.jpg
                    [width] => 595
                    [height] => 397
                )

        )

    [1] => Array
        (
            [img_hd] => Array
                (
                    [url] => /zenphoto/cache/test/2014-04-26_bol-dor-2014_6347_1190_watermark.jpg
                    [width] => 1190
                    [height] => 794
                )

        )

)

Line 515 should be:

printResponsiveImage($img[0]['img_sd'], $img[1]['img_hd'], NULL, NULL, NULL, NULL, $class, $id, $alt);

The same with thumbs and album.php Line 579 should be:

  printResponsiveImage($img[0]['img_sd'], $img[1]['img_hd'], NULL, NULL, NULL, NULL, $class, $id, $alt);

Otherwise, seems to work fine :-) I really appreciate your great work.

acrylian commented 10 years ago

Ah, of course, actually I wanted to avoid this [0]/[1] and just forgot to update the actual return array… ;-)

Fix is up (hopefully ;-)).

Bruno21 commented 10 years ago

The last version is fine ! Thanks!!

acrylian commented 10 years ago

Great, thanks for testing.

Bruno21 commented 10 years ago

Maybe a typo line 545

$croph = getOption('thumb_crop_height', $croph, false);

should be

$croph = setOption('thumb_crop_height', $croph, false);

Also, there isn't a 'HD printAlbumThumbImage' function for index.php (gallery.php). I made one based from printAlbumThumbImage() with a little of getHDImageThumb() and some getResponsiveImage() ;-)