@@ -60,24 +60,52 @@ def test_server_url(plex):
6060
6161
6262def test_server_transcodeImage (tmpdir , plex , movie ):
63- width , height = 500 , 500
64- original_url = plex .url (movie .thumb )
65- resize_url = plex .transcodeImage (movie .thumb , height , width )
66- grayscale_url = plex .transcodeImage (movie .thumb , height , width , saturation = 0 )
63+ width , height = 500 , 100
64+ background = "000000"
65+
66+ original_url = movie .thumbUrl
67+ resize_jpeg_url = plex .transcodeImage (original_url , height , width )
68+ no_minSize_png_url = plex .transcodeImage (original_url , height , width , minSize = False , imageFormat = "png" )
69+ grayscale_url = plex .transcodeImage (original_url , height , width , saturation = 0 )
70+ opacity_background_url = plex .transcodeImage (original_url , height , width , opacity = 0 , background = background , blur = 100 )
71+ online_no_upscale_url = plex .transcodeImage (
72+ "https://raw.githubusercontent.com/pkkid/python-plexapi/master/tests/data/cute_cat.jpg" , 1000 , 1000 , upscale = False )
73+
6774 original_img = download (
6875 original_url , plex ._token , savepath = str (tmpdir ), filename = "original_img" ,
6976 )
70- resized_img = download (
71- resize_url , plex ._token , savepath = str (tmpdir ), filename = "resize_image"
77+ resized_jpeg_img = download (
78+ resize_jpeg_url , plex ._token , savepath = str (tmpdir ), filename = "resized_jpeg_img"
79+ )
80+ no_minSize_png_img = download (
81+ no_minSize_png_url , plex ._token , savepath = str (tmpdir ), filename = "no_minSize_png_img"
7282 )
7383 grayscale_img = download (
7484 grayscale_url , plex ._token , savepath = str (tmpdir ), filename = "grayscale_img"
7585 )
76- with Image .open (resized_img ) as image :
77- assert width , height == image .size
86+ opacity_background_img = download (
87+ opacity_background_url , plex ._token , savepath = str (tmpdir ), filename = "opacity_background_img"
88+ )
89+ online_no_upscale_img = download (
90+ online_no_upscale_url , plex ._token , savepath = str (tmpdir ), filename = "online_no_upscale_img"
91+ )
92+
7893 with Image .open (original_img ) as image :
79- assert width , height != image .size
94+ assert image .size [0 ] != width
95+ assert image .size [1 ] != height
96+ with Image .open (resized_jpeg_img ) as image :
97+ assert image .size [0 ] == width
98+ assert image .size [1 ] != height
99+ assert image .format == "JPEG"
100+ with Image .open (no_minSize_png_img ) as image :
101+ assert image .size [0 ] != width
102+ assert image .size [1 ] == height
103+ assert image .format == "PNG"
80104 assert _detect_color_image (grayscale_img , thumb_size = 150 ) == "grayscale"
105+ assert _detect_dominant_hexcolor (opacity_background_img ) == background
106+ with Image .open (online_no_upscale_img ) as image1 :
107+ with Image .open (utils .STUB_IMAGE_PATH ) as image2 :
108+ assert image1 .size == image2 .size
81109
82110
83111def _detect_color_image (file , thumb_size = 150 , MSE_cutoff = 22 , adjust_color_bias = True ):
@@ -101,6 +129,15 @@ def _detect_color_image(file, thumb_size=150, MSE_cutoff=22, adjust_color_bias=T
101129 return "blackandwhite"
102130
103131
132+ def _detect_dominant_hexcolor (file ):
133+ # https://stackoverflow.com/questions/3241929/python-find-dominant-most-common-color-in-an-image
134+ pilimg = Image .open (file )
135+ pilimg .convert ("RGB" )
136+ pilimg .resize ((1 , 1 ), resample = 0 )
137+ rgb_color = pilimg .getpixel ((0 , 0 ))
138+ return "{:02x}{:02x}{:02x}" .format (* rgb_color )
139+
140+
104141def test_server_fetchitem_notfound (plex ):
105142 with pytest .raises (NotFound ):
106143 plex .fetchItem (123456789 )
0 commit comments