Skip to content

Commit

Permalink
Première utilisation d'un fork de spritezero
Browse files Browse the repository at this point in the history
  • Loading branch information
laem committed Jan 20, 2025
1 parent aebdbd2 commit f58a99d
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 0 deletions.
Binary file modified bun.lockb
Binary file not shown.
48 changes: 48 additions & 0 deletions lib/buildSprites.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import fs from 'fs'
import glob from 'glob'
import path from 'path'
import spritezero from '@jutaz/spritezero'

const pixelRatios = [1, 2]

pixelRatios.forEach(function (pxRatio) {
var svgs = ['restaurant', 'cafe']
// .sync(path.resolve(path.join(__dirname, 'input/*.svg')))
.map(function (id) {
return {
svg: fs.readFileSync(
path.resolve(path.join(__dirname, '../public/icons/' + id + '.svg'))
),
id,
}
})

var pngPath = path.resolve(
path.join(__dirname, '../public/sprite/sprite-cartes@' + pxRatio + '.png')
)
var jsonPath = path.resolve(
path.join(__dirname, '../public/sprite/sprite-cartes@' + pxRatio + '.json')
)

// Pass `true` in the layout parameter to generate a data layout
// suitable for exporting to a JSON sprite manifest file.
spritezero.generateLayout(
{ imgs: svgs, pixelRatio: pxRatio, sdf: true, format: true },
function (err, dataLayout) {
if (err) return
fs.writeFileSync(jsonPath, JSON.stringify(dataLayout))
}
)

// Pass `false` in the layout parameter to generate an image layout
// suitable for exporting to a PNG sprite image file.
spritezero.generateLayout(
{ imgs: svgs, pixelRatio: pxRatio, sdf: true, format: false },
function (err, imageLayout) {
spritezero.generateImage(imageLayout, function (err, image) {
if (err) return
fs.writeFileSync(pngPath, image)
})
}
)
})
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"@babel/plugin-syntax-import-attributes": "^7.26.0",
"@babel/runtime": "^7.25.9",
"@dwayneparton/geojson-to-gpx": "^0.2.0",
"@jutaz/spritezero": "^9.0.0",
"@mapbox/polyline": "^1.2.1",
"@mapbox/sphericalmercator": "^2.0.0",
"@mdx-js/loader": "^3.1.0",
Expand Down Expand Up @@ -84,6 +85,7 @@
"jsdom": "^25.0.1",
"maplibre-gl": "5",
"maplibre-gl-indoorequal": "^1.3.0",
"mapnik": "^4.5.9",
"next": "15.1.4",
"next-contentlayer2": "v0.5.3",
"next-mdx-remote": "^5.0.0",
Expand Down
1 change: 1 addition & 0 deletions public/sprite/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"cafe":{"width":15,"height":15,"x":0,"y":0,"pixelRatio":1},"restaurant":{"width":15,"height":15,"x":15,"y":0,"pixelRatio":1}}
Binary file added public/sprite/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/sprite/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"cafe":{"width":30,"height":30,"x":0,"y":0,"pixelRatio":2},"restaurant":{"width":30,"height":30,"x":30,"y":0,"pixelRatio":2}}
Binary file added public/sprite/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f58a99d

Please sign in to comment.