mirror of
https://github.com/metafy-social/python-scripts.git
synced 2025-01-18 23:37:04 +00:00
Add files via upload
Image Resizer Using Python
This commit is contained in:
parent
3108d05d03
commit
da11f60058
7
scripts/readme.md
Normal file
7
scripts/readme.md
Normal file
|
@ -0,0 +1,7 @@
|
|||
Image Resizer Using Python
|
||||
So, I was working on this one project where I needed to place equal size images. To make it look good.
|
||||
|
||||
But doing one picture at a time is such a waste. So, I created this simple script to make this easy for me.
|
||||
Dependencies
|
||||
|
||||
Only dependecy is OpenCV2
|
BIN
scripts/resize image.png
Normal file
BIN
scripts/resize image.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 436 KiB |
110
scripts/resize_image.py
Normal file
110
scripts/resize_image.py
Normal file
|
@ -0,0 +1,110 @@
|
|||
# import argparse
|
||||
# import sys
|
||||
# import cv2
|
||||
# import os
|
||||
|
||||
# parser = argparse.ArgumentParser()
|
||||
# parser.add_argument("--src", metavar="source",
|
||||
# help="Source folder of the Image files")
|
||||
# parser.add_argument("--dest", metavar="destinantion",
|
||||
# help="Destination folder of the Image files (Default: Source folder)")
|
||||
# parser.add_argument("--size", metavar="size", nargs='+', type=int,
|
||||
# help="Size of the new image(Width Height)")
|
||||
# parser.add_argument("--ext", metavar="extension", nargs='+',
|
||||
# help="""Extensions of files to be resized (Default: jpg png).
|
||||
# Supported extensions - Extensions Supported by OpenCV.""")
|
||||
# args = parser.parse_args()
|
||||
|
||||
|
||||
# def resize_image(img, size):
|
||||
# """Resize the image to given size
|
||||
# params:
|
||||
# img - array of image pixels
|
||||
# size - tuple => (Width, Height)
|
||||
# """
|
||||
|
||||
# return cv2.resize(img, size, interpolation=cv2.INTER_AREA)
|
||||
|
||||
|
||||
# def load_images(src, ext, size):
|
||||
# """Resize the images in given source folder
|
||||
# and save to the destinantion folder
|
||||
# params:
|
||||
# src - Source folder
|
||||
# ext - Extensions of images to be
|
||||
# """
|
||||
|
||||
# cd = os.getcwd()
|
||||
# os.chdir(src)
|
||||
# files_ls = os.listdir()
|
||||
# files = [file for file in files_ls if ((len(file.split('.')) > 1)
|
||||
# and (file.split('.')[1].lower() in ext))]
|
||||
# res_imgs = []
|
||||
# for file in files:
|
||||
# img = cv2.imread(file)
|
||||
# res_imgs.append((file, resize_image(img, size)))
|
||||
# print("\nResizing Image:", src + file)
|
||||
|
||||
# return res_imgs, cd
|
||||
|
||||
|
||||
# def save_images(cd, imgs, src, dest):
|
||||
# """Save the images to the destination folder
|
||||
# params:
|
||||
# cd - Working Directory where program resides
|
||||
# imgs - list of Tuples => (image name, image)
|
||||
# src - Source of the image files
|
||||
# dest - destinantion folder of the image
|
||||
# """
|
||||
# os.chdir(cd)
|
||||
# os.chdir(dest)
|
||||
# for img in imgs:
|
||||
# cv2.imwrite(img[0], img[1])
|
||||
# print("\nSaving Image:", src + img[0],
|
||||
# "To", dest + img[0])
|
||||
|
||||
|
||||
# if args.src == None:
|
||||
# sys.exit("Path source Folder Missing")
|
||||
|
||||
|
||||
# if args.dest == None:
|
||||
# args.dest = args.src
|
||||
|
||||
|
||||
# if args.size == None:
|
||||
# sys.exit("New image size missing.")
|
||||
|
||||
|
||||
# if args.ext == None:
|
||||
# args.ext = ['jpg', 'png']
|
||||
|
||||
|
||||
# imgs, cd = load_images(args.src, args.ext, tuple(args.size))
|
||||
# save_images(cd, imgs, args.src, args.dest)
|
||||
|
||||
|
||||
import cv2
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
image = cv2.imread("D:\image.jpg", 1)
|
||||
# Loading the image
|
||||
|
||||
half = cv2.resize(image, (0, 0), fx=0.1, fy=0.1)
|
||||
bigger = cv2.resize(image, (1050, 1610))
|
||||
|
||||
stretch_near = cv2.resize(image, (780, 540),
|
||||
interpolation=cv2.INTER_NEAREST)
|
||||
|
||||
|
||||
Titles = ["Original", "Half", "Bigger", "Interpolation Nearest"]
|
||||
images = [image, half, bigger, stretch_near]
|
||||
count = 4
|
||||
|
||||
for i in range(count):
|
||||
plt.subplot(2, 2, i + 1)
|
||||
plt.title(Titles[i])
|
||||
plt.imshow(images[i])
|
||||
|
||||
plt.show()
|
1
scripts/tempCodeRunnerFile.py
Normal file
1
scripts/tempCodeRunnerFile.py
Normal file
|
@ -0,0 +1 @@
|
|||
matplotlib.pyplot
|
Loading…
Reference in New Issue
Block a user