MATLAB: How do i save URL’s of Images at a specific size into a sub-folder of the choosing

imageurl

I have a text file called :
ImageURLS.txt
And after reading in the text file using the line:
urlsToImgs = importdata('ImageURLS.txt');
This gives me a cell 1400 x 1 of urls in the form "http:// … .jpg"
I want to take these URL's of images and save them at a specific size (227 x 227) then save them to a specific sub-folder (Images)
for i = 1:1%length(urlsToImgs)
outfilename = websave(['PosImage: ', num2str(i)],['' urlsToImgs{i} '']);
end
This is the code I tried to use but it throws the error:
Error using fopen
The file name contains characters that are not contained in the filesystem encoding.
Certain operations may not work as expected.
I dont believe this is the way to do what im asking however, and would like to know how to do so better.

Best Answer

I would recommend using webread, imresize and imwrite functions to do this task. I think the solution would be looks like:
% Example
url = 'http://heritage.stsci.edu/2007/14/images/p0714aa.jpg';
subfolderPath = 'C:\folder1\folder2';
fileName = '1.jpg';
% Read image from URL, resize it to 227x227 and save in the subfolder
I = webread(url);
I = imresize(I,[227 227]);
imwrite(I,fullfile(subfolderPath,fileName));