How to use #nuxt/image with image from assets - image

I try to use #nuxt/image with image from assets folder; when using image from static folder or external url, the image is optimised as well; but when on using it on image from assets like below:
<nuxt-img
src="~assets/img/Icone-accueil/row_left.svg"
alt=""
class="float-left margin-fleche"
quality="30"
/>
I have this result in my html
<img src="/_ipx/q_30/_nuxt/assets/img/Icone-accueil/row_left.svg" alt="" class="float-left margin-fleche">
but the image doesn't appear

Using #nuxt/image with images from the assets/ folder does not work.
The following is from the #nuxt/image documentation:
Images should be stored in the static/ directory of your project.
For example, when using <nuxt-img src="/nuxt-icon.png" />, it should
be placed in static/ folder under the path static/nuxt-icon.png.
Image stored in the assets/ directory are not proccessed with Nuxt
Image because those images are managed by webpack.

From nuxt documentation:
Inside your ‍‍vue templates, if you need to link to your assets
directory use ~/assets/your_image.png with a slash before assets.
In your case:
<nuxt-img
src="~/assets/img/Icone-accueil/row_left.svg"
alt=""
class="float-left margin-fleche"
quality="30"
/>
Another quote from nuxt:
When working with dynamic images you will need to use require
<img :src="require(`~/assets/img/${image}.jpg`)" />
In your case check this out:
<nuxt-img
:src="require(`~/assets/img/Icone_accueil/row_left.svg`)"
alt=""
class="float-left margin-fleche"
quality="30"
/>

As per Nuxt Image doc, default direcrtory for images is /static, you can change it by update nuxt.config file as below.
e.g,
image: {
dir: 'assets/images',
},
Now you can rewrite as,
<nuxt-img
src="/Icone-accueil/row_left.svg"
alt=""
class="float-left margin-fleche"
quality="30"
/>

This worked for me:
< img :src="require (~/assets/image.jpeg)"
alt=""
/>

For Nuxt3 users whom are using the edge version, which is v1, of nuxt/image,
if you are self-hosting, place images in the 'public' directory as opposed to 'static'.
Quote from v1 docs:
With default provider, you should put /nuxt-icon.png inside public/ directory for >Nuxt 3 make the above example work.
v0 (Nuxt2)
/static/images/myImage.jpg
v1 (Nuxt3)
/public/images/myImage.jpg
Then, access images in the same way others have described. Nuxt/image v1 does not seem able to read a dir named static and of course doesn't read assets as that is used by Webpack.

Related

Laravel 5.5 image is not showing from storage/app

I am using laravel 5.5. I have a form to upload image. Those images are storing into the storage/app folder. It is working fine. But when I try to show those images. Those are not showing.
I have tried with those ways to print my images.
<img src="{{ asset('storage/1539872957.a-nice-place-to-picnic.jpg')}}" alt="">
<img class="user_avatar" src="{{ url('storage/app/1539872897.IMG_20180804_120323.jpg') }}">
<img class="user_avatar" src="<?php echo asset('storage/1539455504.prakruth-resort.jpg');?>">
Here I am giving image name as static name just for checking.
I have also done php artisan storage:link and a shortcut folder named 'storage' is created in the public folder. But still images are not showing.
i think this Answer would help you.
you will have to create symlink from public/storage to storage/app/public first through this command
`php artisan storage:link`
Now any file in /storage/app/public can be accessed via a link like:
http://somedomain.com/storage/image.jpg
In your Controller use public driver like this:
\Storage::disk('public')->put('file.png',file_get_contents($request->file->getRealPath()));
the above file.png would be stored in 'public/storage'.
now you can access the image file like this:
<img src="{{ asset('storage/file.png'); }}" />

Jekyll/Kramdown image location in file system

I'm using Jekyll with Kramdown on Github, and I want to insert an image in my page. So I use
![img1](img1.jpg)
and include img1.jpg in the folder _posts
The generated HTML is
<p> <img src="img1.jpg" alt="img1" /> </p>
but then the link is
http://username.github.io/projectname/2017/04/27/img1.jpg
and this link does not exist. How can I correct it?
Put image somewhere else (e.g. /images/ directory) and then insert it as ![img1](/images/img1.jpg).

Image not displaying in view. Laravel

In my Laravel project I'm trying to load an image into my view using blade but it displays as a broken link. I inspect it with firebug and the src is pointing to the image but nothing is displaying.
My image is located in my project's public/images/users/3/profilePictures/
Here is my <img> in the view.blade.php
<img class="com-profile-picture" src="images/users/{{ $follower->id }}/profilePictures/50thumb-{{ $follower->profilePicture->url }}" alt="{{ $follower->first_name }} {{ $follower->last_name }} Profile" width="50" height="50">
However I get this when I load the page:
When I inspect the image with firebug I see this:
That is the correct src and the image does exist in my public/images/users/3/profilePictures/ directory
Anyone know why this is happening?
This may be caused you are in a route which does not represent the base URL. You should generate the URL for your assets relative to the public/ folder. Use URL::asset('path/to/asset') to generate the URL.
{{ URL::asset("images/users/{$follower->id}/profilePictures/50thumb-{$follower->profilePicture->url}") }}
Or as #lukasgeiter mentioned you can simply use asset('path/to/asset') helper.
You can try with the
php artisan storage:link
else you can use this
A simple fix for the issue (linked broken error)
in .env file
APP_URL=http://localhost
this replace with the
APP_URL=http://localhost:8000
then the issue will be fixed.
delete already generated symlink and then run this command
php artisan storage:link
if you are using laravel, consider excluding public folder or any folder where your public files are store in .htacccess from folders that laravel control.
Do it like this in .htaccess
# Exclude directory from rewriting RewriteRule ^(public/) - [L]
Storage location before (Not Working) :
<img src="{{asset('storage/app/public/media/productImages/'.$list->image)}}" alt="" srcset="">
Working storage location :
<img src="{{asset('storage/media/productImages/'.$list->image)}}" alt="" srcset="">
Else try :
Deleting all the linked/shortcut folders created in public folder
Then recreating the link by running :
php artisan storage:link

File path in CodeIgniter

Im having a hard time with a link to a video file in one of my CI views.
Videos folder is in CodeIgniter root directory. When I link the video file name as following, everything works fine.
<source type="video/mp4" src="/videos/<?= $video->filename ?>" />
But I need to be able to link a file, that is outside of CI root folder, for example somewhere else on C disk, like C:/videos. Cant figure out how to do it. Thanks in advance.
Edit:
Ill be a little bit more specific.
My codeigniter app will be placed on a server in WEB directory:
/something1/something2/web/
Now Video Files folder will be placed on a same level as WEB folder:
/something1/something2/videos/
I want to link videos that are in Videos folder, which is on a same level as WEB(CI root) folder.
If your videos folder is outside your CI-install, you could set the video dir as a config item in /config/config.php:
$config['video_dir'] = 'http://example.com/videos';
You can then retrieve it in your controller like this:
$data['video_dir'] = $this->config->item('video_dir');
(Or you could just have a videos folder inside the CI directory...)
Try It
<source type="video/mp4" src="<?php echo base_url(); ?>videos/<?= $video->filename ?>" />

image file path in php

I am new to web development / php.
I want to show an image if the image is in root folder its ok by the following script.
<img src='photo_1.png' alt='nayaad_logo' width='100' height='100' align='top' />
but if I place it in a folder it is not displayed:
<img src='/ad_photos/photo_1.png' alt='nayaad_logo' width='100' height='100' align='top' />
how to display an image from a different folder?
Regards:
"ad_photos" folder probably isn't in your web root folder.
try this:
<img src='ad_photos/photo_1.png' alt='nayaad_logo' width='100' height='100' align='top' />

Resources