Remote Image field settings default to '0 for width and height. This causes images to not display.

Currently the module sets the width and height to '0' and this are required to have values. If the remote image dimensions are not known then the module should obtain them and enter the value programmatically.

Patch attached to add getimagesize() function to retrieve remote image dimensions if values left blank/0.

Comments

quantumized created an issue. See original summary.

3cwebdev’s picture

Issue summary: View changes
StatusFileSize
new981 bytes
3cwebdev’s picture

Status: Active » Needs review
tucho’s picture

Title: Remote Image field settings default to '0 for width and height - causes images to not display. » Image invisible when using default size values
StatusFileSize
new4.22 KB
new4.5 KB

I have made another aproach to this problem, taking into account the possibility that getimagesize may not be available or it can not have access to remote files.

The patch that I uploaded only adds the #width and #height indexes on the field render array when they have a non empty value.

This change takes advantage of the logic of the template_preprocess_image function (defined in the file core/includes/theme.inc), which only adds the corresponding attribute to the img tag if it is defined on the render array:

  foreach (['width', 'height', 'alt', 'title', 'sizes'] as $key) {
    if (isset($variables[$key])) {
      // If the property has already been defined in the attributes,
      // do not override, including NULL.
      if (array_key_exists($key, $variables['attributes'])) {
        continue;
      }
      $variables['attributes'][$key] = $variables[$key];
    }
  }

If the width attribute and the height attribute is not set, the browser would use the original image size.

If the width attribute or the height attribute is not set, the browser would use defined dimension, resizing the other proportionally.

I have also modified the RemoteImageWithMetadataFormatter, so it explains what was mentioned previously.

nicolash’s picture

I've successfully tested both separately. A combination of the 2 approaches would be great, as in first see if getimagesize works and if so use that. If not use the approach in #4 of not setting anything.

Either way, both are better than the current state, which probably won't work for most people unless they always manually get the dimensions and enter them.

nicolash’s picture

Status: Needs review » Reviewed & tested by the community
gaurav.kapoor’s picture

Status: Reviewed & tested by the community » Needs work

I am inclined towards going with the solution provided in #4. The patch would require a reroll and removal of some of the changes it is introducing as those have been pushed as part of other commits.

  • gaurav.kapoor committed 320f45f on 8.x-1.x authored by tucho
    Issue #2909193 by tucho, 3CWebDev, NicolasH, gaurav.kapoor: Image...
gaurav.kapoor’s picture

Status: Needs work » Fixed

Pushed the fix for this. Thanks for working on this module.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.