U
U
Uncle Vanya2019-04-15 10:31:19
JavaScript
Uncle Vanya, 2019-04-15 10:31:19

How to convert images to base64 and save to file?

Hello dear.
1) I need to take pictures from a certain folder.
2) Convert them all to base64 in a specific file
3) In the file, they must be written to an object (which we will create ourselves with the name IMAGES)
4) The command should look like this:

gulp base64-images folderName (folderName -аргумент(путь от куда берутся картинки))

I did it at a gallop. I couldn't find it with webpack.
Now the code looks like this:
const gulp = require('gulp');
var gulpBase64 = require("gulp-to-base64");

gulp.task('base64-images', function(args) {
    return gulp.src("./assets/konan/images/*.{png,jpg,jpeg,mp3,svg,ttf}")
        .pipe(gulpBase64({
            outPath: "images.js" //output file path
        }))
});

It takes a hardcoded picture from the folder (I can’t figure out how to pass it as an argument)
And it just shoves it into the file into the object, how can I put the object into a variable?)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question