Skip to content

Commit

Permalink
use websave to avoid errors with imread from DALL•E URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
ccreutzi committed Jun 5, 2024
1 parent a29429d commit 93fcbae
Showing 1 changed file with 12 additions and 2 deletions.
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 93fcbae

Please sign in to comment.