You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I found out that if I load an image using the ImageObject it renders small and blurred when the image metadata dpi is 300. If I change the dpi of the image to 72 outside drawbot (without changing the number of pixels) drawbot renders it as the actual image. I found a solution by loading the image using TIFFRepresentation instead of the current method in the _makeBitmapImageRep function. This method always keeps the right size regardless of the input image dpi metadata. This code sample only overrides the function _makeBitmapImageRep to show the difference. I'm not sure what would be the other effects of this change:
importAppKitfromdrawBot.miscimportDrawBotError, optimizePathimportQuartzimportosfromdrawBotimport*fromdrawBot.context.tools.imageObjectimportImageObjectdef_makeBitmapImageRep(nsImage=None, pdfPage=None, imageResolution=72.0, antiAliasing=False, colorSpaceName=AppKit.NSCalibratedRGBColorSpace):
"""Construct a bitmap image representation at a given resolution."""ifnsImageisNoneandpdfPageisNone:
raiseDrawBotError("At least a image or a pdf page must be provided to create a bitmap representaion.")
ifpdfPageisnotNone:
mediaBox=pdfPage.boundsForBox_(Quartz.kPDFDisplayBoxMediaBox)
width, height=mediaBox.sizeelifnsImageisnotNone:
width, height=nsImage.size()
rep=AppKit.NSBitmapImageRep.imageRepWithData_(nsImage.TIFFRepresentation())
returnrepdef_open(self, path):
""" Open an image with a given `path`. """ifisinstance(path, AppKit.NSImage):
im=pathelifisinstance(path, str):
path=optimizePath(path)
ifpath.startswith("http"):
url=AppKit.NSURL.URLWithString_(path)
else:
ifnotos.path.exists(path):
raiseDrawBotError("Image path '%s' does not exists."%path)
url=AppKit.NSURL.fileURLWithPath_(path)
im=AppKit.NSImage.alloc().initByReferencingURL_(url)
else:
raiseDrawBotError("Cannot read image path '%s'."%path)
rep=_makeBitmapImageRep(im)
ciImage=AppKit.CIImage.alloc().initWithBitmapImageRep_(rep)
self._merge(ciImage, doCrop=True)
# remove the following line to see the default behaviorImageObject.open=_openimagePath="sampleImage-300dpi.jpg"i=ImageObject()
i.open(imagePath)
w, h=imageSize(i)
size(w, h)
The text was updated successfully, but these errors were encountered:
I found out that if I load an image using the
ImageObject
it renders small and blurred when the image metadata dpi is 300. If I change the dpi of the image to 72 outside drawbot (without changing the number of pixels) drawbot renders it as the actual image. I found a solution by loading the image usingTIFFRepresentation
instead of the current method in the_makeBitmapImageRep
function. This method always keeps the right size regardless of the input image dpi metadata. This code sample only overrides the function_makeBitmapImageRep
to show the difference. I'm not sure what would be the other effects of this change:The text was updated successfully, but these errors were encountered: