Skip to content

Commit 06bcae6

Browse files
committed
Edit image opening method to read its data
1 parent 968d9b3 commit 06bcae6

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

altify.egg-info/PKG-INFO

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 1.1
22
Name: altify
3-
Version: 3.9
3+
Version: 4.2
44
Summary: Uses deep learning to caption img tags within a web page and fills out their alt attribute with the related caption
55
Home-page: https://github.com/parhamp/altify
66
Author: Parham Pourdavood
@@ -25,9 +25,8 @@ Description: Altify
2525
Dependencies
2626
------------
2727

28-
- BeautifulSoup
2928
- Python 2.7
30-
- html5lib
29+
- BeautifulSoup
3130

3231
Install and Usage (Latest Version)
3332
----------------------------------
@@ -51,18 +50,16 @@ Description: Altify
5150
~~~~~~~~~
5251

5352
A new HTML file called altify.html is created next to the HTML file you
54-
selected. (Or Desktop, when using older versions)
53+
selected.
5554

5655
How It was Built
5756
----------------
5857

5958
1. Parses the html using BeautifulSoup.
60-
2. Find all the image tags.
61-
3. Stream images using uploads.im API, and then with its URL, send
62-
request to Microsoft's API to caption.
63-
4. Filter images that are smaller than 200px width.
64-
5. Fill out the alt attributes for all the images.
65-
6. Write an edited HTML file next to the file you selected.
59+
2. Finds all the image tags.
60+
3. Sends a request to Microsoft's API to caption.
61+
4. Fills out the alt attributes for all the images.
62+
5. Writes an edited HTML file next to the file you selected.
6663

6764
Captioned Images Samples
6865
------------------------

altify/altify

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,15 @@ def caption(image_file, api_key, html_file):
8282
data = json.dumps({"Url": image_file}, separators=(',', ':'))
8383
else:
8484
if os.path.isabs(image_file):
85-
data = open(image_file, 'rb')
85+
with open(image_file, 'rb') as f:
86+
data = f.read()
8687
else:
8788
# If the image's path is relative we will find its absolute path
88-
# by joining it to the html_file's abs path.
89+
# by joining it to the html_file's abs path.
8990
dir_path = os.path.dirname(os.path.realpath(html_file))
9091
image_file = os.path.join(dir_path, image_file)
91-
data = open(image_file, 'rb')
92+
with open(image_file, 'rb') as f:
93+
data = f.read()
9294
try:
9395
conn = httplib.HTTPSConnection('api.projectoxford.ai')
9496
conn.request("POST", "/vision/v1.0/describe?%s" %

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
setup(
77
name = 'altify',
88
packages=['altify'],
9-
version = '4.1',
9+
version = '4.2',
1010
scripts=['altify/altify'],
1111
description = "Uses deep learning to caption img tags within a web page and fills out their alt attribute with the related caption",
1212
long_description=long_description,

0 commit comments

Comments
 (0)