From da3b95065b2ca9c7c5b3180750ad5c0d2e92b3d0 Mon Sep 17 00:00:00 2001 From: Sarah Date: Fri, 9 Sep 2022 21:31:26 +0100 Subject: [PATCH 1/6] add test script --- get_file.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 get_file.py diff --git a/get_file.py b/get_file.py new file mode 100644 index 0000000..9dcd496 --- /dev/null +++ b/get_file.py @@ -0,0 +1,14 @@ +import base64 +from svglib.svglib import svg2rlg +from reportlab.graphics import renderPDF, renderPM +import cairosvg + +file = "vcinema_map.svg" + +import pyvips + +image = pyvips.Image.new_from_file(file) + +tn = image.thumbnail_image(1000, crop=pyvips.Interesting.ALL) + +tn.write_to_file("x.png") \ No newline at end of file -- 2.40.1 From ed07915a4dbc51e0daafd8737641d3a66f210680 Mon Sep 17 00:00:00 2001 From: Sarah Date: Fri, 9 Sep 2022 21:31:40 +0100 Subject: [PATCH 2/6] add changes - DOESNT WORK --- wiki_pages/FilmsByCountry.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/wiki_pages/FilmsByCountry.py b/wiki_pages/FilmsByCountry.py index c6d0592..8fe7282 100644 --- a/wiki_pages/FilmsByCountry.py +++ b/wiki_pages/FilmsByCountry.py @@ -8,6 +8,7 @@ import warnings from bookstack import Bookstack from vcinema_utils import VCinemaUtils +import pyvips warnings.filterwarnings("ignore") @@ -94,9 +95,14 @@ def draw_map(films_by_country, file_name="vcinema_map.svg"): worldmap.plot(countries, cmap=["#FF4000"], opacity=opacity, filename=file_name, verbose=False) - with Image(filename=file_name, width=1000, height=655) as i: - png_data = i.make_blob("png") + image = pyvips.Image.new_from_file(file_name) + + tn = image.thumbnail_image(1000, crop=pyvips.Interesting.ALL) + + img_buffer = tn.write_to_memory() + + img = img_buffer[:] os.remove(file_name) - return png_data + return img -- 2.40.1 From 573c1cd990471893a354d1e55fc1890380faa0d5 Mon Sep 17 00:00:00 2001 From: Sarah Date: Fri, 9 Sep 2022 21:42:53 +0100 Subject: [PATCH 3/6] make some changes --- get_file.py | 5 ++++- wiki_pages/FilmsByCountry.py | 4 +--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/get_file.py b/get_file.py index 9dcd496..349a2e6 100644 --- a/get_file.py +++ b/get_file.py @@ -11,4 +11,7 @@ image = pyvips.Image.new_from_file(file) tn = image.thumbnail_image(1000, crop=pyvips.Interesting.ALL) -tn.write_to_file("x.png") \ No newline at end of file +img_buffer = tn.write_to_buffer(".png") + +with open("b.png", "wb") as f: + f.write(img_buffer) diff --git a/wiki_pages/FilmsByCountry.py b/wiki_pages/FilmsByCountry.py index 8fe7282..a3095e7 100644 --- a/wiki_pages/FilmsByCountry.py +++ b/wiki_pages/FilmsByCountry.py @@ -99,9 +99,7 @@ def draw_map(films_by_country, file_name="vcinema_map.svg"): tn = image.thumbnail_image(1000, crop=pyvips.Interesting.ALL) - img_buffer = tn.write_to_memory() - - img = img_buffer[:] + img = tn.write_to_buffer(".png") os.remove(file_name) -- 2.40.1 From ead6655b7b77a1e2975fe3b7de11a3551d1a1720 Mon Sep 17 00:00:00 2001 From: Sarah Date: Fri, 9 Sep 2022 21:44:10 +0100 Subject: [PATCH 4/6] Delete get_file.py --- get_file.py | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 get_file.py diff --git a/get_file.py b/get_file.py deleted file mode 100644 index 349a2e6..0000000 --- a/get_file.py +++ /dev/null @@ -1,17 +0,0 @@ -import base64 -from svglib.svglib import svg2rlg -from reportlab.graphics import renderPDF, renderPM -import cairosvg - -file = "vcinema_map.svg" - -import pyvips - -image = pyvips.Image.new_from_file(file) - -tn = image.thumbnail_image(1000, crop=pyvips.Interesting.ALL) - -img_buffer = tn.write_to_buffer(".png") - -with open("b.png", "wb") as f: - f.write(img_buffer) -- 2.40.1 From 00a50f7ce5822226002c842e402a4d61059b632d Mon Sep 17 00:00:00 2001 From: Sarah Date: Fri, 9 Sep 2022 22:42:52 +0100 Subject: [PATCH 5/6] refactor --- wiki_pages/FilmsByCountry.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/wiki_pages/FilmsByCountry.py b/wiki_pages/FilmsByCountry.py index a3095e7..081473c 100644 --- a/wiki_pages/FilmsByCountry.py +++ b/wiki_pages/FilmsByCountry.py @@ -2,13 +2,12 @@ import base64 from collections import Counter, OrderedDict import csv import os -from wand.image import Image +import pyvips import worldmap import warnings from bookstack import Bookstack from vcinema_utils import VCinemaUtils -import pyvips warnings.filterwarnings("ignore") @@ -97,10 +96,11 @@ def draw_map(films_by_country, file_name="vcinema_map.svg"): image = pyvips.Image.new_from_file(file_name) - tn = image.thumbnail_image(1000, crop=pyvips.Interesting.ALL) + # Crop image + image = image.thumbnail_image(1000, crop=pyvips.Interesting.ALL) - img = tn.write_to_buffer(".png") + png_data = image.write_to_buffer(".png") os.remove(file_name) - return img + return png_data -- 2.40.1 From 417f81d6a527efa8f4a6360ed04ba3036c26e7f9 Mon Sep 17 00:00:00 2001 From: Sarah Date: Fri, 9 Sep 2022 22:43:18 +0100 Subject: [PATCH 6/6] remove comment --- wiki_pages/FilmsByCountry.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/wiki_pages/FilmsByCountry.py b/wiki_pages/FilmsByCountry.py index 081473c..0d33842 100644 --- a/wiki_pages/FilmsByCountry.py +++ b/wiki_pages/FilmsByCountry.py @@ -95,8 +95,6 @@ def draw_map(films_by_country, file_name="vcinema_map.svg"): worldmap.plot(countries, cmap=["#FF4000"], opacity=opacity, filename=file_name, verbose=False) image = pyvips.Image.new_from_file(file_name) - - # Crop image image = image.thumbnail_image(1000, crop=pyvips.Interesting.ALL) png_data = image.write_to_buffer(".png") -- 2.40.1