Skip to content

Commit

Permalink
Merge pull request #40 from matlab-deep-learning/websave-to-get-images
Browse files Browse the repository at this point in the history
Websave to get images
  • Loading branch information
ccreutzi authored Jun 6, 2024
2 parents 0509cc5 + 93fcbae commit bebf8b2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Binary file modified examples/UsingDALLEToGenerateImages.mlx
Binary file not shown.
14 changes: 12 additions & 2 deletions openAIImages.m
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ function mustBeValidSize(this, imagesize)
% Output the images
if isfield(response.Body.Data.data,"url")
urls = arrayfun(@(x) string(x.url), response.Body.Data.data);
images = arrayfun(@imread,urls,UniformOutput=false);
images = arrayfun(@myImread,urls,UniformOutput=false);
else
images = [];
end
Expand Down Expand Up @@ -357,4 +357,14 @@ function mustBeValidFileType(filePath)
function mustBeNonzeroLengthTextScalar(content)
mustBeNonzeroLengthText(content)
mustBeTextScalar(content)
end
end

function data = myImread(URI)
% imread usually, but not always, fails to read from the
% https://oaidalleapiprodscus.blob.core.windows.net URLs returned by
% DALL•E. Use websave instead.
filename = tempname + ".png";
clean = onCleanup(@() delete(filename));
websave(filename,URI);
data = imread(filename);
end

0 comments on commit bebf8b2

Please sign in to comment.