MCPcopy Create free account
hub / github.com/PageBot/PageBot / path2ScaledImagePath

Function path2ScaledImagePath

Lib/pagebot/toolbox/transformer.py:615–647  ·  view source on GitHub ↗

Answer the path where scaled images go to, also altering their name. If extension is different from the path extension, then replace it. If w, h, index or extension are set, then add them to the output name. If basePath is None, then used the default ./scaled/ instead. >>> path2Scal

(path, w=None, h=None, index=None, extension=None, scaledPath=None)

Source from the content-addressed store, hash-verified

613 return path.split('.')[-1].lower()
614
615def path2ScaledImagePath(path, w=None, h=None, index=None, extension=None, scaledPath=None):
616 """Answer the path where scaled images go to, also altering their name. If
617 extension is different from the path extension, then replace it. If w, h,
618 index or extension are set, then add them to the output name. If basePath
619 is None, then used the default ./scaled/ instead.
620
621 >>> path2ScaledImagePath('images/myImage.jpg')
622 'scaled/myImage.jpg'
623 >>> path2ScaledImagePath('images/myImage.jpg', 100, 200)
624 'scaled/myImage-w100-h200.jpg'
625 >>> path2ScaledImagePath('images/myImage.jpg', 100, 200, 12, 'png')
626 'scaled/myImage-w100-h200-i12.png'
627 >>> path2ScaledImagePath('images/myImage.jpg', 100, 200, 12, 'jpg', scaledPath='anotherPath')
628 'anotherPath/myImage-w100-h200-i12.jpg'
629 """
630 if scaledPath is None:
631 scaledPath = 'scaled/'
632 elif not scaledPath.endswith('/'):
633 scaledPath += '/'
634 if extension is None:
635 extension = path2Extension(path)
636 fileName = '.'.join(path2Name(path).split('.')[:-1])
637 params = []
638 if w:
639 params.append('w%s' % w)
640 if h:
641 params.append('h%s' % h)
642 if index is not None:
643 params.append('i%s' % index)
644 params = '-'.join(params)
645 if params:
646 params = '-' + params
647 return scaledPath + fileName + params + '.' + extension
648
649def path2FontName(path, extensions=None):
650 """

Callers 1

scaleImageMethod · 0.90

Calls 3

path2ExtensionFunction · 0.85
path2NameFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected