axe312ger / sqip

"SQIP" (pronounced \skwɪb\ like the non-magical folk of magical descent) is a SVG-based LQIP technique.
http://axe312ger.github.io/sqip
The Unlicense
3.37k stars 82 forks source link

plugin-svgo (alone) not working #289

Closed xerc closed 7 months ago

xerc commented 1 year ago

% file test.jpg

JPEG image data, progressive, precision 8, 3543x2731, components 3

% npm list -g

/usr/local/lib
├── npm@9.6.6
├── sqip-cli@1.0.0-alpha.46
├── sqip-plugin-data-uri@1.0.0-alpha.42
├── sqip-plugin-svgo@1.0.0-alpha.43
├── sqip@1.0.0-alpha.41
└── svgo@3.0.2

% DEBUG=sqip* sqip -i test.jpg -p svgo


sqip-cli Found plugins:
sqip-cli  [ 'svgo' ] +0ms
sqip Loading sqip-plugin-svgo +0ms
sqip-cli Generated CLI options:
sqip-cli [..] +93ms
sqip-cli Parsed CLI args:
sqip-cli  {
width: 300,
silent: false,
'parseable-output': false,
input: 'test.jpg',
plugins: [ 'svgo' ]
} +2ms
sqip-cli Final sqip options: {
input: 'test.jpg',
output: 'test.svg',
width: 300,
plugins: [ { name: 'svgo', options: {} } ],
silent: false,
parseableOutput: false
} +0ms
sqip input test.jpg is a file. Skip file search. +0ms
sqip Found files: +95ms
sqip [ 'test.jpg' ] +0ms
sqip check file test.jpg +0ms
Processing: test.jpg
sqip Loading sqip-plugin-svgo +2s
sqip Construct svgo +178ms
sqip Apply svgo +0ms
SvgoParserError: <input>:1:1: Non-whitespace before first tag.

1 | ����C
| ^
2 |
3 |

SvgoParserError: :1:1: Non-whitespace before first tag. at sax.onerror (/usr/local/lib/node_modules/sqip-cli/node_modules/svgo/lib/parser.js:244:19) at emit (/usr/local/lib/node_modules/sqip-cli/node_modules/@trysound/sax/lib/sax.js:518:35) at error (/usr/local/lib/node_modules/sqip-cli/node_modules/@trysound/sax/lib/sax.js:549:5) at strictFail (/usr/local/lib/node_modules/sqip-cli/node_modules/@trysound/sax/lib/sax.js:573:7) at beginWhiteSpace (/usr/local/lib/node_modules/sqip-cli/node_modules/@trysound/sax/lib/sax.js:847:7) at SAXParser.write (/usr/local/lib/node_modules/sqip-cli/node_modules/@trysound/sax/lib/sax.js:902:11) at parseSvg (/usr/local/lib/node_modules/sqip-cli/node_modules/svgo/lib/parser.js:256:7) at optimize (/usr/local/lib/node_modules/sqip-cli/node_modules/svgo/lib/svgo.js:34:15) at Object.optimize (/usr/local/lib/node_modules/sqip-cli/node_modules/svgo/lib/svgo-node.js:97:10) at SVGOPlugin.apply (/usr/local/lib/node_modules/sqip-cli/node_modules/sqip-plugin-svgo/dist/sqip-plugin-svgo.js:25:31)



fyi/ it ignores to always use `primitive`
xerc commented 1 year ago

& output into stdout does not work as descr. @ https://github.com/axe312ger/sqip/#output

axe312ger commented 1 year ago

Yes, SVGO expects a svg to be input. If you pass an JPG, it does not know what to do with it. You first need to use a plugin that transforms pixels into vectors, like the pixelator plugin or the primitive plugin. Then you can use the svgo plugin to minimize the SVG data

xerc commented 1 year ago

yea ; but sqip -i input.jpg is possible & therefore its a bit confusing may consider primitive as fallback if potrace | pixels are not used

axe312ger commented 1 year ago

yea ; but sqip -i input.jpg is possible & therefore its a bit confusing may consider primitive as fallback if potrace | pixels are not used

I see your point, but when you don't pass any plugins, it runs the default set of plugins.

We might make it more clear by outputting which plugins are used when running the command