-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new_from_source keeps a ref to the source
Since it might be a custom source with callabcks, and the python wrapper for the source class must stay alive. Added another example of custom sources.
- Loading branch information
Showing
3 changed files
with
39 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import sys | ||
import gc | ||
import requests | ||
import pyvips | ||
|
||
URL = "https://cdn.filestackcontent.com/bnTGtQw5ShqMPpxH2tMw" | ||
URLS = [URL] * int(sys.argv[1]) | ||
|
||
session = requests.Session() | ||
|
||
image = pyvips.Image.black(1500, 1500) | ||
|
||
for i, url in enumerate(URLS): | ||
print(f"loading {url} ...") | ||
stream = session.get(url, stream=True).raw | ||
|
||
source = pyvips.SourceCustom() | ||
source.on_read((lambda stream: stream.read)(stream)) | ||
|
||
tile = pyvips.Image.new_from_source(source, "", access="sequential") | ||
image = image.composite2(tile, "over", x= 50 * (i + 1), y= 50 * (i + 1)) | ||
|
||
print(f"writing output.jpg ...") | ||
image.write_to_file("output.jpg") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters