Scripts: support .png-uploads in imgur-to-panoramax script
This commit is contained in:
parent
3c90d33b9d
commit
a0feed3695
2 changed files with 14 additions and 7 deletions
|
@ -137,6 +137,7 @@ export class ImgurToPanoramax extends Script {
|
||||||
if (!v) {
|
if (!v) {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
const isPng = v.endsWith(".png")
|
||||||
|
|
||||||
const imageHash = v.split("/").at(-1).split(".").at(0)
|
const imageHash = v.split("/").at(-1).split(".").at(0)
|
||||||
{
|
{
|
||||||
|
@ -151,7 +152,9 @@ export class ImgurToPanoramax extends Script {
|
||||||
}
|
}
|
||||||
|
|
||||||
let path: string = undefined
|
let path: string = undefined
|
||||||
if (existsSync(this._imageDirectory + "/" + imageHash + ".jpg")) {
|
if (isPng) {
|
||||||
|
path = this._imageDirectory + "/../imgur_png_images/jpg/" + imageHash + ".jpg"
|
||||||
|
} else if (existsSync(this._imageDirectory + "/" + imageHash + ".jpg")) {
|
||||||
path = this._imageDirectory + "/" + imageHash + ".jpg"
|
path = this._imageDirectory + "/" + imageHash + ".jpg"
|
||||||
} else if (existsSync(this._imageDirectory + "/" + imageHash + ".jpeg")) {
|
} else if (existsSync(this._imageDirectory + "/" + imageHash + ".jpeg")) {
|
||||||
path = this._imageDirectory + "/" + imageHash + ".jpeg"
|
path = this._imageDirectory + "/" + imageHash + ".jpeg"
|
||||||
|
@ -164,7 +167,7 @@ export class ImgurToPanoramax extends Script {
|
||||||
license = await this.getLicenseFor(v)
|
license = await this.getLicenseFor(v)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Could not fetch license due to", e)
|
console.error("Could not fetch license due to", e)
|
||||||
if(e === 404){
|
if (e === 404) {
|
||||||
console.log("NOT FOUND")
|
console.log("NOT FOUND")
|
||||||
return new Tag(key, "")
|
return new Tag(key, "")
|
||||||
}
|
}
|
||||||
|
@ -174,6 +177,10 @@ export class ImgurToPanoramax extends Script {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
const sequence = this.sequenceIds[license.licenseShortName?.toLowerCase()]
|
const sequence = this.sequenceIds[license.licenseShortName?.toLowerCase()]
|
||||||
|
console.log("Reading ",path)
|
||||||
|
if(!existsSync(path)){
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
const handle = await open(path)
|
const handle = await open(path)
|
||||||
const stat = await handle.stat()
|
const stat = await handle.stat()
|
||||||
|
|
||||||
|
@ -262,12 +269,12 @@ export class ImgurToPanoramax extends Script {
|
||||||
|
|
||||||
const bounds = new BBox([
|
const bounds = new BBox([
|
||||||
[
|
[
|
||||||
5.051208080670676,
|
-180,
|
||||||
45.55085138791583
|
-90
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
14.998934008628453,
|
180,
|
||||||
55.163232765096495
|
90
|
||||||
]
|
]
|
||||||
])
|
])
|
||||||
const maxcount = 10000
|
const maxcount = 10000
|
||||||
|
|
|
@ -95,7 +95,7 @@ export class Imgur extends ImageProvider {
|
||||||
withResponse?: (obj) => void
|
withResponse?: (obj) => void
|
||||||
): Promise<LicenseInfo> {
|
): Promise<LicenseInfo> {
|
||||||
const url = providedImage.url
|
const url = providedImage.url
|
||||||
const hash = url.substr("https://i.imgur.com/".length).split(/\.jpe?g/i)[0]
|
const hash = url.substr("https://i.imgur.com/".length).split(/(\.jpe?g)|(\.png)/i)[0]
|
||||||
|
|
||||||
const apiUrl = "https://api.imgur.com/3/image/" + hash
|
const apiUrl = "https://api.imgur.com/3/image/" + hash
|
||||||
const response = await Utils.downloadJsonCached<{
|
const response = await Utils.downloadJsonCached<{
|
||||||
|
|
Loading…
Reference in a new issue