It is very convenient to write programs with MATLAB to make gif animations with arbitrary settings, only a dozen lines of code.
Demo1:
The example shows a change from 1 to 10, with a texture attached, the code is as follows:
%% gif images can only display 256 colors, so only index images are supported filename = 'mygif'; image = uint8(255*zeros(480,640)); image = cat(3,image,image,image); for i = 1:10 %% text RGB = insertText(image,[200,240],num2str(i),... 'FontSize',100,'font','LucidaSansRegular','BoxColor',... 'green','TextColor','red'); %% write [im,map] = rgb2ind(RGB,255); if i==1 imwrite(im,map,filename,'gif','LoopCount',inf,'DelayTime',1); else imwrite(im,map,filename,'gif','WriteMode','append','DelayTime',1); end end
Demo2:
This is the official timing, please wait patiently~
function createGIF2() % Create a personalized GIF animation Demo % A = ones(480,480); positions = 0.4*[size(A,2),size(A,1)]; positions(2,:) = 0.1*[size(A,2),size(A,1)]; dispnumber = 10:-1:0; image = imread('lena.jpg');% Enter your own image here Num = length(dispnumber); imageNum = 1;%length(imds.Files); for i = 1:Num+imageNum if i<= Num RGB = insertText(A,positions,{num2str(dispnumber(i)),'Please wait...'},... 'BoxOpacity',0,... 'FontSize',60,... 'textcolor','r',... 'Font','Simsun');% 宋体 else C = {'Am I beautiful? ',' Still looking at me? ',' Still looking at me? ? '}; str = sprintf('%s\n%s\n%s',C{:}); RGB = insertText(image,0.07*[size(image,2),size(image,1)],... str,... 'BoxOpacity',0,... 'FontSize',100,... 'Font','STXingkai',...% Chinese Xingkai font 'TextColor','g'); RGB = imresize(RGB,size(A)); end %% write [ind,map] = rgb2ind(RGB,255); if i == 1 imwrite(ind,map,'mygif1.gif','gif',... 'LoopCount',inf,... 'DelayTime',0.8); elseif i == Num+imageNum imwrite(ind,map,'mygif1.gif','gif',... 'WriteMode','append',... 'DelayTime',3); else imwrite(ind,map,'mygif1.gif','gif',... 'WriteMode','append',... 'DelayTime',1); end end
Demo3:
In addition, a more gorgeous MATLAB logo dynamic diagram is attached, as follows: