Skip to content

Instantly share code, notes, and snippets.

@maforget
Last active January 27, 2023 10:21
Show Gist options
  • Save maforget/63558612d19410c9807d6e87a494cf4a to your computer and use it in GitHub Desktop.
Save maforget/63558612d19410c9807d6e87a494cf4a to your computer and use it in GitHub Desktop.
Plugin for ComicRack to find the image resolution from a comic
import clr
import System
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import MessageBox
#@Name Find Image Resolution
#@Key FindImageResolution
#@Hook Books
#@Enabled false
#@Description Find the resolution of the images
def FindImageResolution (books):
for book in books:
res = FindResolution(book)
if res:
print "Resolution=" + str(res[0]) + "x" + str(res[1])
book.ScanInformation = str(res[0]) + "px"
#### Alternative way, replace above line with one from these to suit your need (just remove the # before) ####
# book.ScanInformation += " " + str(res[0]) + "px" # To append instead, Be careful to rerun, no parsing logic and if empty will add a space at the beginning
# book.Notes = str(res[0]) + "px"
# book.ScanInformation = str(res[0]) + "x" + str(res[1]) # Width x Height
# book.SetCustomValue("ImageSize", str(res[0]) + "x" + str(res[1])) # Alternative to using Book Information, using a Custom Value instead
# book.SetCustomValue("ImageSizeWidth", str(res[0]) + "px")
# book.SetCustomValue("ImageSizeHeight", str(res[1]) + "px")
def FindResolution(book):
newList = []
pageCount = len(list(book.GetPageList())) if book.IsLinked else 0
print "book= " + book.Series + if_else(book.Number != "", " [" + book.Number + "]", "") + if_else(book.Title != "", " - " + book.Title, "") + " // pageCount=" + str(pageCount)
for i in range(0, pageCount):
page = book.GetPage(i)
width, height = 0, 0
if page.ImageWidth > 0 or page.ImageHeight > 0:
width = page.ImageWidth
height = page.ImageHeight
else:
page2 = ComicRack.App.GetComicPage(book,i)#If ComicRack hasn't scanned the book yet we need to do this instead because we will get a resolution of 0 in that case
width = page2.Width
height = page2.Height
length = width, height
if length[0] != 0:
newList.append(length)
#print "width=" + str(width) + " // height=" + str(height) + " // length=" + str(length) + " // page=" + str(i + 1) + " // PageType=" + str(page.PageType)
if len(newList) > 0:
return max(newList,key=newList.count)
else:
return False
def if_else(condition, trueVal, falseVal):
if condition:
return trueVal
else:
return falseVal
@maforget
Copy link
Author

Redone plugin, check this out instead https://github.com/maforget/ComicRack_FindImageResolution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment