Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remote image gets: *resources.genericResource is not an image #9275

Closed
regisphilibert opened this issue Dec 11, 2021 · 6 comments · Fixed by #9278
Closed

Remote image gets: *resources.genericResource is not an image #9275

regisphilibert opened this issue Dec 11, 2021 · 6 comments · Fixed by #9278

Comments

@regisphilibert
Copy link
Member

regisphilibert commented Dec 11, 2021

What version of Hugo are you using (hugo version)?

hugo v0.90.1-48907889+extended darwin/amd64 BuildDate=2021-12-10T10:56:41Z VendorInfo=gohugoio

Does this issue reproduce with the latest release?

Yes

I'm trying to fetch an image remotely (https://images.unsplash.com/photo-1611323593958-0fec16fa2909) and grab its .Width and .Height or use .Resize. But the following ensue: error calling Width: *resources.genericResource is not an image or error calling Resize: *resources.genericResource is not an image

Note that MainType and SubType are image and jpeg respectively.

This might be because the URL do not point to a file per say, but and endpoint serving a file. But then, the MainType/SubType are misleading and prevent any testing before trying to apply image transformation.

  {{ with resources.Get "https://images.unsplash.com/photo-1611323593958-0fec16fa2909" }}
  {{ with .Err }}
    {{ warnf "%s" . }}
  {{ else }}
    {{ with .Resize "300x"}}
    <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
    {{ end }}
  {{ end }}
@jmooring
Copy link
Member

{{ with resources.Get "https://images.unsplash.com/photo-1611323593958-0fec16fa2909" }}
  {{ .RelPermalink }} --> /photo-1611323593958-0fec16fa2909_5636203134359007483.jpe
{{ end }}

The extension is jpe.

@regisphilibert
Copy link
Member Author

Which might be what causes the error, but if you download the image, you'll see that the file's extension is jpg. If this is indeed a JPE file, and Hugo does not support, we should be able to test this through MainType/SubType or else.

@eyllanesc
Copy link

Which might be what causes the error, but if you download the image, you'll see that the file's extension is jpg. If this is indeed a JPE file, and Hugo does not support, we should be able to test this through MainType/SubType or else.

It seems that the browser infers the type of the image if the path does not have an extension, so it adds .jpg. If you use wget, you get the binary file without an extension whose operation is similar to what hugo does.

@regisphilibert
Copy link
Member Author

Interesting. So maybe the problem is that the Hugo returns a SubType of jpg?

@jmooring
Copy link
Member

jmooring commented Dec 12, 2021

When we retrieve this image, this is what happens.

  1. Determine the MIME type (image/jpeg) from the response header.
  2. Determine the extension from the MIME type. But with image/jpeg there are several possibilities, so we try something else.
  3. Determine the extension from the file name. But this file doesn't have an extension, so we try something else.
  4. Determine the MIME type (again) by looking at the first 512 bytes.
  5. Determine the extension from the MIME type. But with image/jpeg there are several possibilities, so we pick the first one.

On Ubuntu, the sorted list of extensions associated with image/jpeg is .jpe, .jpg, and jpeg. The last two are Go built-ins, but the list is augmented by the OS (that's where .jpe comes from).

So, the first extension on the list is .jpe, and Hugo doesn't treat that as an image.

Similar py challenge:
https://bugs.python.org/issue1043134

jmooring added a commit to jmooring/hugo that referenced this issue Dec 12, 2021
jmooring added a commit to jmooring/hugo that referenced this issue Dec 13, 2021
Add jpe, jif, and jfif to image/jpeg extensions.
For remote image/jpeg without extension, always use jpg extension.

Closes gohugoio#9275
@bep bep closed this as completed in #9278 Dec 13, 2021
bep pushed a commit that referenced this issue Dec 13, 2021
Add jpe, jif, and jfif to image/jpeg extensions.
For remote image/jpeg without extension, always use jpg extension.

Closes #9275
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants