✨ add paper size
This commit is contained in:
@@ -21,6 +21,7 @@ parser.add_argument("-i","--ignore-temp", action="store_true", help="[requires -
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-f", "--img-format", type=str, default="png", help="use output custom img format"
|
"-f", "--img-format", type=str, default="png", help="use output custom img format"
|
||||||
)
|
)
|
||||||
|
parser.add_argument("-p","--paper-size", type=str, default="A4", help="set paper size")
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
src = args.source
|
src = args.source
|
||||||
@@ -29,6 +30,7 @@ verbose = args.verbose
|
|||||||
alt_temp = args.alt_temp
|
alt_temp = args.alt_temp
|
||||||
ignore_temp = args.ignore_temp
|
ignore_temp = args.ignore_temp
|
||||||
img_format = args.img_format
|
img_format = args.img_format
|
||||||
|
paper_size = args.paper_size
|
||||||
|
|
||||||
if verbose:
|
if verbose:
|
||||||
logging.basicConfig(level=logging.DEBUG, format="[%(levelname)s] - %(message)s")
|
logging.basicConfig(level=logging.DEBUG, format="[%(levelname)s] - %(message)s")
|
||||||
|
|||||||
+33
-11
@@ -1,7 +1,7 @@
|
|||||||
from utils import Download
|
from utils import Download
|
||||||
from utils import Misc
|
from utils import Misc
|
||||||
from utils import log
|
from utils import log
|
||||||
from utils import src, dest, alt_temp, img_format, ignore_temp, verbose
|
from utils import src, dest, alt_temp, img_format, ignore_temp, verbose, paper_size
|
||||||
|
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
import tempfile
|
import tempfile
|
||||||
@@ -17,8 +17,11 @@ import shutil
|
|||||||
# src: str = "https://www.youtube.com/watch?v=tyloC0e-Tqk"
|
# src: str = "https://www.youtube.com/watch?v=tyloC0e-Tqk"
|
||||||
# dest: str = "/home/sakamoto/Public/test"
|
# dest: str = "/home/sakamoto/Public/test"
|
||||||
|
|
||||||
|
|
||||||
class Vid2Sheet:
|
class Vid2Sheet:
|
||||||
def __init__(self, src, dest, img_format: str, use_tempfile=True, ignore_temp=False):
|
def __init__(
|
||||||
|
self, src, dest, img_format: str, use_tempfile=True, ignore_temp=False
|
||||||
|
):
|
||||||
self.src = src
|
self.src = src
|
||||||
self.dest = dest
|
self.dest = dest
|
||||||
self.img_format = img_format
|
self.img_format = img_format
|
||||||
@@ -72,7 +75,7 @@ class Vid2Sheet:
|
|||||||
def run(self):
|
def run(self):
|
||||||
self.check()
|
self.check()
|
||||||
self.capture()
|
self.capture()
|
||||||
self.stitch()
|
self.stitch(paper_size)
|
||||||
self.convert()
|
self.convert()
|
||||||
|
|
||||||
def check(self):
|
def check(self):
|
||||||
@@ -159,10 +162,25 @@ class Vid2Sheet:
|
|||||||
self.video.release()
|
self.video.release()
|
||||||
log.info("Analysis complete")
|
log.info("Analysis complete")
|
||||||
|
|
||||||
def stitch(self, dpi=300):
|
def stitch(self, paper_size="A4", dpi=300):
|
||||||
log.info("Attempting to stitch by three for every group...")
|
log.info("Attempting to stitch by three for every group...")
|
||||||
letter_width = int(8.5 * dpi)
|
log.info(f"Chosen paper size: {paper_size}")
|
||||||
letter_height = int(11 * dpi)
|
|
||||||
|
paper_sizes = {
|
||||||
|
"letter": (8.5, 11),
|
||||||
|
"A4": (8.27, 11.69),
|
||||||
|
"legal": (8.5, 14),
|
||||||
|
"tabloid": (11, 17),
|
||||||
|
}
|
||||||
|
|
||||||
|
if paper_size in paper_sizes:
|
||||||
|
width_inches, height_inches = paper_sizes[paper_size]
|
||||||
|
else:
|
||||||
|
log.error(f"Unsupported paper size '{paper_size}'. Using default 'A4'.")
|
||||||
|
width_inches, height_inches = paper_sizes["A4"]
|
||||||
|
|
||||||
|
letter_width = int(width_inches * dpi)
|
||||||
|
letter_height = int(height_inches * dpi)
|
||||||
|
|
||||||
image_files = sorted(os.listdir(self.raw_dir))
|
image_files = sorted(os.listdir(self.raw_dir))
|
||||||
|
|
||||||
@@ -185,18 +203,22 @@ class Vid2Sheet:
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
img_height, img_width = img.shape[:2]
|
img_height, img_width = img.shape[:2]
|
||||||
|
|
||||||
scale_factor = min(
|
scale_factor = min(
|
||||||
letter_width / img_width, available_height / img_height
|
letter_width / img_width, available_height / img_height
|
||||||
)
|
)
|
||||||
|
|
||||||
resized_img_width = int(img_width * scale_factor)
|
resized_img_width = int(
|
||||||
resized_img_height = int(img_height * scale_factor)
|
img_width * scale_factor * 0.95
|
||||||
|
)
|
||||||
|
resized_img_height = int(img_height * scale_factor * 0.95)
|
||||||
resized_img = cv2.resize(img, (resized_img_width, resized_img_height))
|
resized_img = cv2.resize(img, (resized_img_width, resized_img_height))
|
||||||
|
|
||||||
x_offset = (letter_width - resized_img_width) // 2
|
x_offset = (letter_width - resized_img_width) // 2
|
||||||
y_offset = (
|
y_offset = int(
|
||||||
available_height - resized_img_height
|
(available_height - resized_img_height) // 2
|
||||||
) // 2 + i * available_height
|
+ i * available_height * 0.9
|
||||||
|
)
|
||||||
|
|
||||||
canvas[
|
canvas[
|
||||||
y_offset : y_offset + resized_img_height,
|
y_offset : y_offset + resized_img_height,
|
||||||
|
|||||||
Reference in New Issue
Block a user