ついでにサイズ変更の部分も行と列に指定しました。
file = 'ngc6543a.jpg';
img = imread(file);
numrows = height(img);
numcols = width(img);
% 拡張子の置き換え
name = replace(file,'.','_');
% 180度ずつ360度まで回す
for i= 1:2
angle = 180*i;
figure();
% ファイル名
str = [name,'_',num2str(i)];
name_jpg = join(str);
% looseは中心ずれない、cropはズレる
imgr_loose = imrotate(img,angle,'crop');
%サイズ変更トライ(1280/1334) -> 行と列でサイズ変更
imgr_size = imresize(imgr_loose,[numrows numcols]);
% 余白なくして表示
imshow(imgr_size,'Border','tight');
% 書き換えたもの
% saveas(gcf,name_jpg,'jpg');
% close(gcf)
imwrite(imgr_size,[name_jpg,'.jpg']);
end