Closed ThePeach closed 6 years ago
I don't know if it fixes your problem, but you can certainly simplify your task as follows:
gulp.task('buildPreviews', function() {
const folders = ['photo', 'vector', 'illustration', 'pixelart'];
const glob = `${paths.images.src}/{${folders.join(',')}}/preview/*.png`
return gulp.src(glob)
.pipe(responsive(
{
'**/*.png': [
{
width: 120,
rename: {
prefix: 'half/'
}
}
]
},
{
progressive: true,
withMetadata: false,
errorOnEnlargement: false,
errorOnUnusedConfig: false,
errorOnUnusedImage: false
}
)
)
.pipe(gulp.dest(paths.images.dest));
});
thanks @TheDancingCode, your code works without crashing, but unfortunately it doesn't adapt to my situation, as I would need to save the images in different subfolders: in your case I would get all the processed images in the same folder.
Also, please note that before upgrading to gulp4 I had no problems running multiple instances of gulp-responsive. Whether that's a problem specific to gulp4 or to a recent upgrade of gulp-responsive, I have no idea. I'll try to do a bit of regression testing as soon as I have some time.
In the meantime any help is greatly appreciated.
Did I understand correctly that you're trying to go from a folder structure like this one:
src/
+ images/
+ illustration/
| + previews/
| + img1.png
+ photo/
| + previews/
| + img2.png
+ pixelart/
| + previews/
| + img3.png
+ vector/
+ previews/
+ img4.png
to one that looks like this?:
dist/
+ images/
+ illustration/
| + previews/
| + half/
| + img1.png
+ photo/
| + previews/
| + half/
| + img2.png
+ pixelart/
| + previews/
| + half/
| + img3.png
+ vector/
+ previews/
+ half/
+ img4.png
Because that works over here. What's your paths.images.src
and paths.images.dest
?
currently they're set to src/images/
and dist/images/
respectively
I don't get it then. This works perfectly here, which is essentially the same as what I posted earlier, and generates the folder structure above:
gulp.task('buildPreviews', function() {
return gulp.src('src/images/{photo,vector,illustration,pixelart}/preview/*.png')
.pipe(
responsive(
{
'**/*.png': [
{
width: 120,
rename: {
prefix: 'half/'
}
}
]
},
{
progressive: true,
withMetadata: false,
errorOnEnlargement: false,
errorOnUnusedConfig: false,
errorOnUnusedImage: false
}
)
)
.pipe(gulp.dest('dist/images/'));
});
@TheDancingCode interesting! just tried on another machine, and it works as expected. Now I've modified another task (there's another task that does something similar but with a completely different configuration, see below) and it's not working:
function buildImages () {
const folders = ['photo', 'vector', 'illustration'];
const glob = `${paths.images.src}/{${folders.join(',')}}/*.{png,jpg}`;
return gulp.src(glob)
.pipe(responsive({
'**/*': [ {
width: 320,
rename: {
dirname: 'small',
extname: '.jpg'
},
format: 'jpeg'
}, {
width: 768,
rename: {
dirname: 'medium'
},
withoutEnlargement: true
}, {
width: 1200,
rename: {
dirname: 'large'
},
withoutEnlargement: true
} ]
}, {
quality: 85,
progressive: true,
withMetadata: false,
errorOnEnlargement: false,
errorOnUnusedConfig: false,
errorOnUnusedImage: false
}
))
.pipe(gulp.dest(paths.images.dest));
}
(consider that this task has to avoid picking up anything that is not jpg or png, so I hope the combination of the glob together with the responsive config works.)
[edit] I now even started getting the segmentation fault I had at the beginning... something caching? 😞
In the previous buildPreviews
task I see:
[11:47:22] gulp-responsive: illustration/preview/2012-06-27-tube-10.png -> illustration/preview/half/2012-06-27-tube-10.png
on this task (which is running separately for testing purposes) I now get
[11:56:21] gulp-responsive: illustration/2011-02-football-player.png -> small/2011-02-football-player.jpg
[11:56:21] gulp-responsive: illustration/2011-02-football-player.png -> medium/2011-02-football-player.png
[11:56:21] gulp-responsive: illustration/2011-02-football-player.png -> large/2011-02-football-player.png
(when it works)
I'm baffled.
(And clearing the node_modules
directory does nothing)
And you would like the new task to output like this?
illustration/2011-02-football-player.png -> illustration/small/2011-02-football-player.jpg
illustration/2011-02-football-player.png -> illustration/medium/2011-02-football-player.png
illustration/2011-02-football-player.png -> illustration/large/2011-02-football-player.png
The dirname
option overrides the full dirname. Use the prefix
option like I did earlier. Like this:
gulp.task('buildImages', function () {
const folders = ['photo', 'vector', 'illustration'];
const glob = `${paths.images.src}/{${folders.join(',')}}/*.{png,jpg}`;
return gulp.src(glob)
.pipe(responsive({
'**/*': [ {
width: 320,
rename: {
prefix: 'small/',
extname: '.jpg'
},
format: 'jpeg'
}, {
width: 768,
rename: {
prefix: 'medium/'
},
withoutEnlargement: true
}, {
width: 1200,
rename: {
prefix: 'large/'
},
withoutEnlargement: true
} ]
}, {
quality: 85,
progressive: true,
withMetadata: false,
errorOnEnlargement: false,
errorOnUnusedConfig: false,
errorOnUnusedImage: false
}
))
.pipe(gulp.dest(paths.images.dest));
});
oooooooh!!!! now I see it! I completely overlooked that! 🤦♂️
OK, then this is totally my fault, every time the task was moving images it was renaming the folder and killing the following copy. Dang. I'm going to close this one!
Thanks a lot for the help @TheDancingCode !!! really appreciated!
This is starting to bug me a bit too much, so I start praying the gods of gulp-responsive, hoping in a solution that can perhaps solve this issue.
I have a (probably) complex situation, and I've detailed it in a post on Stack Overflow.
I've now tried a much simpler approach (at least from a programmatic perspective), with a task that is defined as follows:
When passing just one directory, everything works fine, as soon as I raise the bar, everything crashes randomly with the following error:
The file the error is triggered from seems to vary.
So here I am, desperate :sob:, ignorant of what works behind the scenes and asking: am I doing something wrong?
I thought of writing a single config, but then I don't know how to allow gulp-responsive to write in the right directory...