is it possible to select the screenshots from word document and crop them and then resize them to full page?

2 visualizzazioni (ultimi 30 giorni)
hi,
I am doing bit of learnign through videos on youtube, and taking screenshots of the slide so later on I can review and put comment on it. Is there a way in matlab where i can access the word document select all the screenshots in it and crop them to the size shown in the code below and then resize them A4 page? I found the methodology to do it for one image or can do it if the images are in folder but unsure about how to do it if the screenshots are in word document. file is attached
Code tried so far: (it is wrong because it is a code i used with the folder path and can not work with word file)
images = ['C:\Users\40085772\Desktop\PowerBI_PL300.docx'] ;
N = length(images) ;
I = imread(images(1).name) ;
[x, rect] = imcrop(I) ;
for i = 1:N
I = imread(images(i).name) ;
I2 = imcrop(I,[98.510000000000000,1.875100000000000e+02,1.285980000000000e+03,7.239800000000000e+02]);
end
Error:
Dot indexing is not supported for variables of this type.

Risposta accettata

DGM
DGM il 3 Gen 2023
Modificato: DGM il 3 Gen 2023
Here. I'm sure there are better ways, but it seems to be simple enough that I can get away with directly editing the file.
% document is zipped so that the forum editor allows it; unzip it
unzip('Testing.zip')
% document itself is a zip archive; unzip it to a temp directory
tempdir = 'docxdump';
unzip('Testing.docx',tempdir)
% get the location of the embedded images
dirinfo = dir(fullfile(tempdir,'word/media/*.png'));
nfiles = numel(dirinfo);
% crop them and put them back
for k = 1:nfiles
thisfname = fullfile(dirinfo(k).folder,dirinfo(k).name);
thispict = imread(thisfname);
thispict = imcrop(thispict,[108 194 1263 710]);
imwrite(thispict,thisfname);
end
% take the contents of the temp directory and re-zip it
outfilename = 'modified';
dirinfo = dir(fullfile(tempdir,'*'));
dirinfo = dirinfo(~ismember({dirinfo.name},{'.','..'}));
zip([outfilename '.docx'],{dirinfo.name},tempdir)
movefile([outfilename '.docx.zip'],[outfilename '.docx'])
% remove the temp directory
rmdir(tempdir,'s')
At least that works in this simple case. The image objects are simply scaled to fit the same existing rectangular region in the document. If the cropped images had an aspect ratio that differed from the uncropped images, there would be problems.

Più risposte (1)

Praharshita
Praharshita il 3 Gen 2023
Hi muhammad,
I understand that you are facing an issue while reading the image.
Try using imread to read the image.
images=Imread('C:\Users\40085772\Desktop\PowerBI_PL300.docx')
I hope this helps.
  1 Commento
DGM
DGM il 3 Gen 2023
Modificato: DGM il 3 Gen 2023
Can you point to an example where imread() accepts .docx files?
I thought this would be a job for actxserver(), but I don't run windows, and neither does the forum editor.

Accedi per commentare.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by