NEXTJS - public images not showing on dynamic routes - image

I have a problem with serving a static image from my public/images folder.
It correctly displays in the files I've been working on so far EXCEPT the dynamic file [itemId].js (shown in the picture below)
The most interesting clue I have is this error in the console.
http://localhost:3000/items/_next/static/image/public/images/banner-big.f496e182c5dd297c1d1c030d9b7436d8.png?auto=format&fit=max&w=1920 404 (Not Found)
It tries to serve from /items, which is not what I want at all...
Does anyone know what's the trick behind this? If you need more informations, let me know.
// in components/Header.js (which is wrapping all of my pages)
import bannerBig from "../public/images/banner-big.png";
// then i use it this way with the Image component from next/image
<Image src={bannerBig} alt="midnight city" width={1920} height={800}/>
The img generated by the <Image /> component looks like this and is the same accross all of my pages:
<img alt="midnight city" src="_next/static/image/public/images/banner-big.f496e182c5dd297c1d1c030d9b7436d8.png?auto=format&fit=max&w=3840" decoding="async" style="position:absolute;top:0;left:0;bottom:0;right:0;box-sizing:border-box;padding:0;border:none;margin:auto;display:block;width:0;height:0;min-width:100%;max-width:100%;min-height:100%;max-height:100%" srcset="_next/static/image/public/images/banner-big.f496e182c5dd297c1d1c030d9b7436d8.png?auto=format&fit=max&w=1920 1x, _next/static/image/public/images/banner-big.f496e182c5dd297c1d1c030d9b7436d8.png?auto=format&fit=max&w=3840 2x">

so I finally fixed the problem by adding a '/' before my static image path so it's always being served from the root
<Image
src={"/" + bannerBig.src}
alt="midnight city"
width={bannerBig.width}
height={bannerBig.height}
/>

Related

Thymeleaf doesn't show images

I'm showing images from resources/static/images/
The weird thing is if I give the path like "/images/milk.png", it shows the image but if I get name from ${}, it doesn't work.
<img class="card-img-top"
th:src="#{/images/${res.getLogo().getUploadFileName()}}"
th:alt="${res.getLogo().getUploadFileName()}" />
it seems res.getLogo().getUploadFileName() is working well. So it will be replaced like /images/milk.png. But it doesn't show the image...
How can I fix this?
One more thing, I know basic Thymleaf path is resources/templates, but how it recognize image when I gave like "/images/milk.png"
If u want to upload static images
th:src="#{images/} + ${res.logo.uploadFileName}"
if you want to upload dynamic images
th:src="#{https://~~~.com/} + ${id}

cant use local image as src laravel-mix vuejs

I have a Vue component located at resources/js/modules/MyComponent.vue and inside it, I'm trying to use a local image as an src for the img tag, and the image is located at public/assets/myproj/image/myimage.png.
I've tried using the following :
<img src="#/assets/myproj/image/myimage.png"/>
<img src="require('assets/myproj/image/myimage.png')"/>
<img src="../../../public/assets/myproj/image/myimage.png"/>
<img src="/assets/myproj/image/myimage.png"/>
but none of them work...
I know this is a straightforward question but I hope someone can help me because I've been trying to find an answer for almost an hour now but I still can't figure it out.
If you want to use this in javascript you can do like this
<img :src='getImage(name)'/>
then you will need to import your image in your javascript code
getImage(name){
return require(`#/assets/myproj/${name}`);
}

HTML:Image won’t display

My image won’t display for no reason. I am a noob but I can’t figure it out. The image loads from the url so I know it’s not that. So I’m pretty sure it’s my problem with the coding.
<body>
<img src=https://www.dropbox.com/s/rm27v6s4nj885qu/IMG_0071.PNG?dl=0
Height=300Width=250>
</body>
Your URL is pointing to non-image resource. It's actually pointing to an HTML document.
In URL, change www by dl and remove ?dl=0.
This is valid image URL :
https://dl.dropbox.com/s/rm27v6s4nj885qu/IMG_0071.PNG
Alternatively, you can replace dl=0 to raw=1. This is also valid image URL:
https://www.dropbox.com/s/rm27v6s4nj885qu/IMG_0071.PNG?raw=1
Not always required but as a good practice I'll suggest using quotes for values. Also as mentioned in comments seperate attributes from each other with white space.
<img src="https://dl.dropbox.com/s/rm27v6s4nj885qu/IMG_0071.PNG"
height="300" width="250"/>
<!--OR-->
<img src="https://www.dropbox.com/s/rm27v6s4nj885qu/IMG_0071.PNG?raw=1" height="300" width"250"/>
source : Mickel's Tutorial
I hope, you must use the url of image, But you are referring the url preview pane of dropbox.
It is the actual url for image.
You also need some improvisation with your code, as below
<body>
<img src="https://uc215f04ebb05efbc98d874fefb2.previews.dropboxusercontent.com/p/thumb/AA767gGwgVfZ9rVS7PJbtIOR3eQsWN4mrXjNjVJH3JKjhI5eE7JOd-eQJwydUx1gPkpE3zkAnMSN3-1KEtFN86x-CdWnREg0mQ6hm7APBCuifux1ECDivRuLkrikn1sY_r20EmBWucKHyy-Ps5VPB8ehkUB6x0y9kSb3QzYpP8fOo7IeyR6IaCYZ66mxrJiUiUtzTAV3ddESpRV7lSRaumsSyVPc4k1RbUBS3-_JDnP8Qv6M42x2g7bZDy9vdhhIOZaO585_XQHegapCJ-8bnwLGt-VEy9nud0avi_gzMSpXxx3EXt_NYTWMfFqfstb2HFMVb7WK7jxkSRSX5eE5ck3Q0bdEPAKp1aPnClU2KqI-OgUea6ApGp4G0H4Q3l3UyOjfomtn-SndAAaUzPbaU1HK/p.png?fv_content=true&size_mode=5" height="300" width="250" />
</body>
It will work without any issue. You are not referring proper url that the actual issue.
Also, keep tag properties in quote "" if required.
Like
<img src="url" height="200" width="300" />
Thanks.

Image files not displaying

In my XAML code I have written this:
<Image Source="/Images/male32.png" Visibility="Visible" />
and my project file structure looks like so:
But my image is just not loading?? As you can see I'm trying to add the male32.png image that I have in the Images folder in my project..
Check the build action of the Image.
Example:
When you use "Build Action" of type "Content" then you access your image in this way:
<Image Stretch="None" Source="/images/appbar.cancel.rest.png"/>
When you use "Build Action" of type "Resource" then you access your image in this way:
<Image Source="/WP7SampleProject3;component/images/appbar.feature.email.rest.png"/>
Okay I figured it out, turns out it didn't have anything to do with the BuildAction property, all I had to do in the image path was add ".." e.g. "../Images/male32.png".
Stupid issue that's not even supposed to be an issue.
Nonetheless I have read that BuildAction could also be a potential reason ones image is not displaying. So worth checking out if you have problems with images not displaying.

grails images absolute path

I have this image in my header template <img src="images/slide-1.jpg" alt="Slide #1" width="175" height="77" />
When the template is used from a gsp file inside the 'main' directory, the image is loaded. Although, if I have the same template being used inside a gsp file inside a controller, the image is not loaded. I have tried to change this:
<img src="images/slide-1.jpg" alt="Slide #1" width="175" height="77" />
to this:
<img src="../images/slide-1.jpg" alt="Slide #1" width="175" height="77" />
and it works, but now the image in the other page don't. Any idea to solve the problem? I know the key must be absolute path. But i've done some searches and found nothing.
You can put your images in resource folder (for example, in YOUR_PROJECT/web-app/images) then access it in gsp by resource tag. By this way you won't have the absolute path problem.
For a concrete example, you can refer this question.
Try "${application.contextPath}/images/slide-1.jpg". It's a semi-absolute path that will work in any of your deployment environments.

Resources