Got a problem with image resources.Get
UPDATE:
I already identified the issue.
If I use resources.Get to in one of the images from a post, it will return a 404 for the rest of the site.
The post processed version will work, yes, but the original version of the image will return a 404.
Can this be a bug?
I’m using the following code to display some of my images in a specific template post (editorial).
The problem is that, somehow, the images in other template posts (d&d, etc) sometimes show, sometimes they simply won’t. I’m not sure where the problem is to be honest, because it kinda looks like it is okay.
If I completely erase the following code from the site, then the images in the posts work. But if I keep this code, the behaviour returns.
This is in my editorial template: (the suspect)
{{ if .Params.article_img }}
{{ if eq .Params.style "regular-comic" }}
{{ $base := print .Section "/img" }}
{{ $path := print .Params.article_img }}
{{ $url := print $base "/" $path "-en-xs.jpg" }}
{{ $image := resources.Get $url }}
{{ with $image }}
{{ $scaled := .Fill "900x420" }}
<div class="articles_img_box">
<img src="{{ $scaled.Permalink }}" class="img-liquid">
</div>
{{ end }}
{{ else if eq .Params.style "regular-full-split-square" }}
{{ $base := print .Section "/img" }}
{{ $path := print .Params.article_img }}
{{ $url := print $base "/" $path "-md.png" }}
{{ $image := resources.Get $url }}
{{ with $image }}
{{ $scaled := .Fill "600x420" }}
<div class="articles_img_box">
<img src="{{ $scaled.Permalink }}" class="img-liquid">
</div>
{{ end }}
{{ else }}
{{ $base := print .Section "/img" }}
{{ $path := print .Params.article_img }}
{{ $url := print $base "/" $path "-xs.jpg" }}
{{ $image := resources.Get $url }}
{{ with $image }}
{{ $scaled := .Fill "600x320" }}
<div class="articles_img_box">
<img src="{{ $scaled.Permalink }}" class="img-liquid">
</div>
{{ end }}
{{ end }}
{{ else }}
<div class="articles_img_box" id="editorial_letter">
<img src="{{ .Site.BaseURL }}img/thefreebundle-{{ .Site.Language }}_tw_fb_card.jpg" class="img-liquid">
</div>
{{ end }}
And this goes in my other templates, where the bug happens:
{{ $base := print .Section "/img" }}
{{ $path := print .Params.article_img }}
{{ $url_xs := print $base "/" $path "-xs.png" }}
{{ $url_md := print $base "/" $path "-md.png" }}
{{ $image_xs := resources.Get $url_xs }}
{{ $image_md := resources.Get $url_md }}
Now, this should show the image path:
{{ $image_md.Permalink }}
Which it actually does, but the liveroad doesn’t shows the image. It says 404 not found (although the path is absolutely right and the image should be there)
In fact, the image that “shows up” is blank and its a 24x24 pixel image (!?!?!??!)
24px × 24px (scaled to 1,115px × 0px)
But if I fingerprint the image, it obviously shows. Maybe it has something to do with browser cache? (though I’m clearing the cache and trying different browsers and the problem keeps happening unless I use fingerprint)
I’m lost here!
EDIT and UPDATE
Found another person having a similar issue in the forum. It appears the problem is I was trying to handle a PNG image. Sometimes it works, others it doesn’t. The person had the same issue, PNG -> .Fill
I switched to jpg and it worked fine for a while, then it went back on doing it again! =(