|
Hi, Bogdan,
To continue the theme started in previous post.
I have tested this algorithm in different cases and it works. And rotation in DPP is not a problem.
I'm not programmer and this BAT file (for Windows) may be not fine, but it works. I've wrote some remarks in the text.
@ echo off
rem 1. put in the folder with CR2 files the folder JPG with jpeg-files obtained after DPP
rem convertation. The names of JPEG-files must be the same with CR2-files.
rem 2. in the same folder put this BAT-file, Exiftool.exe and nConvert.exe
rem (http://www.xnview.com/en/nconvert.html)
rem 3. run BAT-file.
echo ****************** synchronization of EXIF and CanonVRD ********************
rem Synchronization of orientation tags in CR2 files with giving preference
rem to DPP processing. DPP looks on CanonVRD:rotation tag at first.
rem If CanonVRD is not empty, we change in *.cr2 files the value of
rem the tag "exif:orientation" accordingly to the value of the tag "CanonVRD:rotation"
rem If CanonVRD:rotation tag is empty, DPP looks on EXIF anyway - this case
rem we have no need to do something.
exiftool -overwrite_original -s -n -if "$CanonVRD:rotation eq 0" -exif:orientation=1 *.cr2
exiftool -overwrite_original -s -n -if "$CanonVRD:rotation eq 1" -exif:orientation=6 *.cr2
exiftool -overwrite_original -s -n -if "$CanonVRD:rotation eq 2" -exif:orientation=3 *.cr2
exiftool -overwrite_original -s -n -if "$CanonVRD:rotation eq 3" -exif:orientation=8 *.cr2
echo *************************** rotate JPEG to 360 degree ********************
rem After previous section we have either EXIF orientation tag, which is
rem synchronised with CanonVRD, or CanonVRD is empty and Exif is dominating.
rem If EXIF:orientation is empty or equal 1, we have no need to rotate anything.
rem Rotate accordingly to EXIF tag:
rem 1 - 0 degree rotation. We do not rotate
rem 6 - 90 degree rotation CW. We rotate JPEG 270 CW
rem 3 - 180 CW. We rotate JPEG 180 CW
rem 8 - 270 CW. We rotate JPEG 90 CW
rem We use nconvert.exe for rotation, because it rotates not only JPEG itself,
rem but the ThumbNail inside JPEG too. It is just what we need.
rem Unfortunately the program Jpegtran kills thumbnails.
for %%i in (JPG\*.jpg) do (
for /F "DELIMS==" %%k IN ('exiftool -n -s -s -s -exif:orientation %%~ni.cr2') DO (
if %%k==6 (nconvert.exe -jpegtrans rot270 JPG\%%~ni.jpg)
if %%k==3 (nconvert.exe -jpegtrans rot180 JPG\%%~ni.jpg)
if %%k==8 (nconvert.exe -jpegtrans rot90 JPG\%%~ni.jpg)
)
)
echo *****************************renew Width tag ******************************
rem It was detected that in CR2 file tags Width and Height allways have
rem horizontal arrangement. That's why we must renew these tags after
rem properly orientation of JPG files. nConvert does renew these tags after
rem rotation. We may just copy them.
exiftool -overwrite_original -b -tagsfromfile JPG\%%f.jpg "-ImageWidth<$ExifImageWidth" *.cr2
echo ***************************** renew Height tag ******************************
exiftool -overwrite_original -b -tagsfromfile JPG\%%f.jpg "-ImageHeight<$ExifImageHeight" *.cr2
echo ****************************** change thumbnail ***********************************
rem It was detected that processing in Exiftool takes more time if file lenght is bigger.
rem That's why we move operations which makes file bigger to the end of processing.
rem We change in CR2 files thumbnails and previews to the new one which we take from JPEG-files.
rem DPP allways saves thumbnails. If we do resize JPEG images before embedding, we have to be
rem sure that thumbnails are conserved. For instance we can use FastStone for resize (www.faststone
+.org)
rem or mentioned nConvert.exe
exiftool -overwrite_original -b -tagsfromfile JPG\%%f.jpg "-ThumbnailImage<$ThumbnailImage" *.cr2
echo ****************************** change preview ***********************************
exiftool -overwrite_original -b "-PreviewImage<=JPG\%%f.jpg" *.cr2
echo
echo ****************************** the end *****************************************
pause
I have tested this BAT and do not find mistakes yet. Thumbnails, Preview images, RAW data are visible in different programs. May be it will be usefull for you or you will be so kind to give some advice.
Best wishes,
Igor. |