Skip to content
Snippets Groups Projects
Commit 6d253a0e authored by AndersLan's avatar AndersLan
Browse files

removed percentage scaling

parent 04f28c93
No related branches found
No related tags found
1 merge request!44Resolve "downscale images when returning from server"
...@@ -34,38 +34,27 @@ class SalamanderEndpoint(Resource): ...@@ -34,38 +34,27 @@ class SalamanderEndpoint(Resource):
image = cv2.imread(path) image = cv2.imread(path)
# percent of original size #scaling to set size
scale_percent = 40 height, width, _ = image.shape
width = int(image.shape[1] * scale_percent / 100)
height = int(image.shape[0] * scale_percent / 100)
dim = (width, height)
# resize image desired_long_side = 320
resized = cv2.resize(image, dim, interpolation=cv2.INTER_AREA) scaling_factor = 1
encoded = base64.b64encode(cv2.imencode(".jpg", resized)[1]).decode() if width > height:
scaling_factor = desired_long_side / width
else:
scaling_factor = desired_long_side / height
#scaling to set size new_dim = (int(width * scaling_factor), int(height * scaling_factor))
# height, width, _ = image.shape
# # resize image
# desired_long_side = 150 image = cv2.resize(image, new_dim, interpolation=cv2.INTER_AREA)
# scaling_factor = 1
# _, buffer = cv2.imencode('.jpg', image)
# if width > height: encoded = base64.b64encode(buffer)
# scaling_factor = desired_long_side / width
# else:
# scaling_factor = desired_long_side / height
#
# new_dim = (int(width * scaling_factor), int(height * scaling_factor))
#
# # resize image
# image = cv2.resize(image, new_dim, interpolation=cv2.INTER_AREA)
#
# _, buffer = cv2.imencode('.jpg', image)
# encoded = base64.b64encode(buffer)
image_id = os.path.basename(path)[0] image_id = os.path.basename(path)[0]
image_data = {"id": image_id, "url": "data:image/png;base64," + encoded} #Decode her om bestemt størrelse skal brukes image_data = {"id": image_id, "url": "data:image/png;base64," + encoded.decode()}
salamander_images.append(image_data) salamander_images.append(image_data)
salamander_images.sort(key=lambda x: x.get('id')) salamander_images.sort(key=lambda x: x.get('id'))
......
...@@ -39,46 +39,29 @@ class SalamanderImageEndpoint(Resource): ...@@ -39,46 +39,29 @@ class SalamanderImageEndpoint(Resource):
if basename.__contains__(str(image_id)): if basename.__contains__(str(image_id)):
image = cv2.imread(path) image = cv2.imread(path)
if not basename.__contains__("str"): #Scale only original to set size
# percent of original size height, width, _ = image.shape
scale_percent = 20 print(sys.getsizeof(image))
width = int(image.shape[1] * scale_percent / 100)
height = int(image.shape[0] * scale_percent / 100)
dim = (width, height)
# resize image desired_long_side = 320
resized = cv2.resize(image, dim, interpolation=cv2.INTER_AREA) scaling_factor = 1
encoded = base64.b64encode(cv2.imencode(".jpg", resized)[1]).decode() if width > height:
scaling_factor = desired_long_side/width
else:
scaling_factor = desired_long_side/height
image_data = {"url": "data:image/png;base64," + encoded} new_dim = (int(width*scaling_factor), int(height*scaling_factor))
#Scale only original to set size # resize image
# image = cv2.imread(path) image = cv2.resize(image, new_dim, interpolation=cv2.INTER_AREA)
# if not basename.__contains__("str"): print(sys.getsizeof(image))
#
# height, width, _ = image.shape _, buffer = cv2.imencode('.jpg', image)
# print(sys.getsizeof(image)) encoded = base64.b64encode(buffer)
#
# desired_long_side = 320 image_data = {"url": "data:image/png;base64," + encoded.decode()}
# scaling_factor = 1
#
# if width > height:
# scaling_factor = desired_long_side/width
# else:
# scaling_factor = desired_long_side/height
#
# new_dim = (int(width*scaling_factor), int(height*scaling_factor))
#
# # resize image
# image = cv2.resize(image, new_dim, interpolation=cv2.INTER_AREA)
# print(sys.getsizeof(image))
#
# _, buffer = cv2.imencode('.jpg', image)
# encoded = base64.b64encode(buffer)
#
# #encoded = encode(path)[2:-1]
# image_data = {"url": "data:image/png;base64," + encoded.decode()}
salamander_images.append(image_data) salamander_images.append(image_data)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment