add script to import image sizes of existing images
This commit is contained in:
parent
47381da36f
commit
b8c193b5dc
1 changed files with 18 additions and 0 deletions
18
scripts/import_image_sizes.ts
Normal file
18
scripts/import_image_sizes.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import { DB_FILE, DB_PATCHES_DIR, UPLOAD_DIR } from '../src/server/Dirs'
|
||||
import Db from '../src/server/Db'
|
||||
import Images from '../src/server/Images'
|
||||
|
||||
const db = new Db(DB_FILE, DB_PATCHES_DIR)
|
||||
db.patch(true)
|
||||
|
||||
;(async () => {
|
||||
let images = db.getMany('images')
|
||||
for (let image of images) {
|
||||
console.log(image.filename)
|
||||
let dim = await Images.getDimensions(`${UPLOAD_DIR}/${image.filename}`)
|
||||
console.log(await Images.getDimensions(`${UPLOAD_DIR}/${image.filename}`))
|
||||
image.width = dim.w
|
||||
image.height = dim.h
|
||||
db.upsert('images', image, { id: image.id })
|
||||
}
|
||||
})()
|
||||
Loading…
Add table
Add a link
Reference in a new issue