8

I am creating a website with an image slider (owl carousel) and I am looking for a good method to put all the images in my HTML quickly.

I hope so, that there is an alternative method to inputting images, because i have about 40 pictures and adding it manually, by hand, will be very tedious...

Could you guys help me by suggesting tell me a generating app or site or anything?

(I'm using Webstorm, but i didn't find any corresponding feature for this in that.)

Jonathan Lam
  • 16,831
  • 17
  • 68
  • 94
Béla Tóth
  • 117
  • 2
  • 2
  • 7

3 Answers3

9

If the list of files is static (you didn't mention if they are created dynamically or not) and you are using Windows a simple approach like this will do:

for %i in (*.jpg) do echo ^<img src="%i" /^> >> all.html

This will create a all.html file which includes references to your jpgs. Simply run the command from a command line window in the directory where your images are stored.

If you need to have the all.html in some other place either move it there or change to >> C:\files\html\all.html. Another alternative is to add a path in the parenthesis, like (C:\files\images\*.jpg) Don't forget to delete the all.html if necessary because the command shown above will always append to an existing file so you might end up with double entries.

Marged
  • 10,577
  • 10
  • 57
  • 99
  • 1
    What language in this? By `command-line`, I'm assuming this is batch (Windows). Is this also for bash in linux? Or am I completely wrong? – Jonathan Lam Nov 07 '15 at 22:55
  • @Jonathan yes, this is good old MS DOS style batch programming ;-) So it is limited to Windows, yes. – Marged Nov 07 '15 at 22:57
  • @Marged Ah, that's awesome, i was looking for like this, thanks. Can i run this command outside from the folder where the pics are? Because my html files are not in the same folder with the images. So i want the relative paths from the root folder, and the images are on the following path: "root/src/img/refs". This just will be a smoother solution for the "problem". – Béla Tóth Nov 07 '15 at 23:02
  • @Marged Yes, that was what i think. Thank you very much, you saved me a lot of time. – Béla Tóth Nov 07 '15 at 23:25
  • @BélaTóth You are welcome. I saw that you already accepted the answer, thanks for that. You can give it a plus one which will give me even more credits which is quite childish but the reason why most of us are giving answers ;-) – Marged Nov 07 '15 at 23:27
  • @Marged I already gave you plus too, but i have a new account here, so it will be visible later (when i reach higher rank). – Béla Tóth Nov 07 '15 at 23:42
  • @Marged Totally agree about the reputation point... It's all for the REP POINTS. I've been going off with them (3 times >200 rep in the past week!) – Jonathan Lam Nov 08 '15 at 00:23
8

You can't just use HTML for this (the only language tag in your question). You're going to need a server-side language, because they can interact with the server (e.g. reading the filesystem).

PHP is great for this: You can iterate through the folder with the images and dynamically add images, so that you don't have to do it manually.

Here's an example:

<?php
    $files = scandir('path/to/img/directory/');
    foreach($files as $file) {
        if($file !== "." && $file !== "..") {
            echo "<img src='$file' />";
        }
    }
?>
Jonathan Lam
  • 16,831
  • 17
  • 68
  • 94
0

I would use php and make an array and an foreach loop like this:

$pictures = array('linkToPicture1', 'linkToPicture2', 'andSoOn');

foreach ($pictures as $picturelink) {
    echo "<img src=".$picturelink.">";
}

And edit the HTML inside the foreach loop and add all your links in the $pictures array.

  • 2
    The OP wanted to avoid typing the names of the images, I think. So using your solution he does not gain much. – Marged Nov 07 '15 at 23:13