Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show image size (W x H) on image nodes #2699

Merged
merged 2 commits into from
Feb 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/services/litegraphService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,9 @@ export const useLitegraphService = () => {

const shiftY = getImageTop(this)

const IMAGE_TEXT_SIZE_TEXT_HEIGHT = 15
const dw = this.size[0]
const dh = this.size[1] - shiftY
const dh = this.size[1] - shiftY - IMAGE_TEXT_SIZE_TEXT_HEIGHT

if (imageIndex == null) {
// No image selected; draw thumbnails of all
Expand Down Expand Up @@ -581,8 +582,9 @@ export const useLitegraphService = () => {
return
}
// Draw individual
let w = this.imgs[imageIndex].naturalWidth
let h = this.imgs[imageIndex].naturalHeight
const img = this.imgs[imageIndex]
let w = img.naturalWidth
let h = img.naturalHeight

const scaleX = dw / w
const scaleY = dh / h
Expand All @@ -593,7 +595,14 @@ export const useLitegraphService = () => {

const x = (dw - w) / 2
const y = (dh - h) / 2 + shiftY
ctx.drawImage(this.imgs[imageIndex], x, y, w, h)
ctx.drawImage(img, x, y, w, h)

// Draw image size text below the image
ctx.fillStyle = LiteGraph.NODE_TEXT_COLOR
ctx.textAlign = 'center'
const sizeText = `${Math.round(img.naturalWidth)} × ${Math.round(img.naturalHeight)}`
const textY = y + h + 10
ctx.fillText(sizeText, x + w / 2, textY)

const drawButton = (
x: number,
Expand Down
Loading