「解像度で画像を並び替える」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(一部飜訳)
 
(同じ利用者による、間の1版が非表示)
9行目: 9行目:
 
ファイルの回復が完了し、[[リカバリ後のタスク]]スクリプトの助けを借りて画像を復元したら、画像を解像度でソートすると良いでしょう。これにより、撮影した写真、ウェブカメラの画像、またはその他の画像を、解像度が同じ関連画像が多いフォルダにソートできます。
 
ファイルの回復が完了し、[[リカバリ後のタスク]]スクリプトの助けを借りて画像を復元したら、画像を解像度でソートすると良いでしょう。これにより、撮影した写真、ウェブカメラの画像、またはその他の画像を、解像度が同じ関連画像が多いフォルダにソートできます。
   
  +
== 画像に関する情報を収集する ==
== Collect info about images ==
 
   
  +
{{Warning|スクリプトを実行する前に、{{Pkg|feh}} プログラムをインストールしておく必要があります。}}
{{Warning|You must have installed the {{Pkg|feh}} program before running the script.}}
 
   
  +
{{Note|画像に関する情報を収集する速度を上げるために、[[リカバリ後のタスク#チェックサムで一意なファイルのみをリストする|重複しない]]ファイルのリストを使用して重複する画像をスキップできますが、このスクリプトでの mime タイプのチェックを削除し、代わりに拡張子でファイルをチェックするようにする必要があります。}}
{{Note|To speed up collecting info about images you can skip duplicate images by use a list of [[Post recovery tasks#List only unique files by checksum|non duplicate]] files but you will also need to remove mime type check in this script and add check files by extension instead.}}
 
   
 
{{hc|collect-info-about-images.sh|<nowiki>#!/bin/bash
 
{{hc|collect-info-about-images.sh|<nowiki>#!/bin/bash
44行目: 44行目:
 
fi
 
fi
 
</nowiki>}}
 
</nowiki>}}
  +
''$IfDamaged'' 変数は、{{Pkg|feh}} によって返される終了ステータスコードを含みます。
The ''$IfDamaged'' variable contains an exit status code returned by {{Pkg|feh}}.
 
   
 
{{Note|
 
{{Note|
  +
* {{Pkg|feh}} プログラムは、表示可能な視覚データが十分にある場合、画像の一部のエラー、ピクセルデータエラーを無視します。
* The {{Pkg|feh}} program ignores some of errors, pixel data errors, in an image if it contains enough of a readable visual data to be shown.
 
  +
* ピクセルエラーにより、画像の一部または全体が正しく表示されず、誤った色や空白/空き領域が生じ、画像が多かれ少なかれ無用のものになることがよくあります。これは、画像内の破損したデータの量に大きく依存します。}}
* A pixel error makes that a part of an image or a whole image cannot be shown correctly, it causes wrong colors or blank/empty spaces that often makes the image more or less useless, mostly depends on the amount of a corrupted data in it.}}
 
   
You can also install {{AUR|pngcheck}} to check integrity of "PNG, JNG or MNG" and/or {{AUR|jpeginfo}} and use output of errors in the ''$IfDamaged'' variable or modify script to skip adding of damaged files into a {{ic|collect-info-about-images.txt}} file.
+
また、{{AUR|pngcheck}} をインストールして "PNG, JNG, MNG" の整合性をチェックし、および/または {{AUR|jpeginfo}} をインストールし、''$IfDamaged'' 変数のエラー出力を使用するか、破損したファイルを {{ic|collect-info-about-images.txt}} ファイルに追加しないようにスクリプトを変更できます。
   
Example of {{AUR|pngcheck}} check resuslt:
+
{{AUR|pngcheck}} のチェック結果のサンプル:
 
{{bc|<nowiki>./f939799496.png invalid IDAT row-filter type (11)
 
{{bc|<nowiki>./f939799496.png invalid IDAT row-filter type (11)
 
./f939799496.png private (invalid?) IDAT row-filter type (236) (warning)
 
./f939799496.png private (invalid?) IDAT row-filter type (236) (warning)
62行目: 62行目:
 
</nowiki>}}
 
</nowiki>}}
   
Example of {{AUR|jpeginfo}} check result:
+
{{AUR|jpeginfo}} のチェック結果のサンプル:
 
{{bc|f62152912.jpg 5678 x 2829 24bit Exif N 11625509 Corrupt JPEG data: 1074 extraneous bytes before marker 0xd9 [WARNING]
 
{{bc|f62152912.jpg 5678 x 2829 24bit Exif N 11625509 Corrupt JPEG data: 1074 extraneous bytes before marker 0xd9 [WARNING]
 
f124619744.jpg 144 x 119 24bit JFIF N 5813 [OK]
 
f124619744.jpg 144 x 119 24bit JFIF N 5813 [OK]
 
}}
 
}}
{{Note| The {{AUR|jpeginfo}} utility cannot scan directories recursively but can read filenames from a file created by {{ic|find -type f -name "*.jpg">>FileWithPathTo-images.txt}}, calculate their md5sums and has an option that makes it able to remove damaged image files.}}
+
{{Note| {{AUR|jpeginfo}} ユーティリティはディレクトリを再帰的にスキャンできませんが、{{ic|find -type f -name "*.jpg">>FileWithPathTo-images.txt}} で作成されたファイルからファイル名を読み取り、md5sum を計算し、破損した画像ファイルを削除するオプションがあります。}}
  +
スクリプト内の文字列から必要なデータを抽出するには、{{Pkg|sed}} や {{Pkg|gawk}} などの外部プログラムの代わりに、[https://tldp.org/LDP/abs/html/string-manipulation.html expression]を使用して、スクリプトの動作を少し高速化することが望ましいです。例えば、
To extract necessary data from a string in a script is better to use an [https://tldp.org/LDP/abs/html/string-manipulation.html expression] instead of an extern program as {{Pkg|sed}} or {{Pkg|gawk}} to make a script work a little faster, e.g.
 
 
{{bc|1=AA="$(jpeginfo -c f62152912.jpg)";
 
{{bc|1=AA="$(jpeginfo -c f62152912.jpg)";
 
ZZ="${AA/*' [OK]'/}";
 
ZZ="${AA/*' [OK]'/}";
76行目: 76行目:
 
}}
 
}}
   
The ''collect-info-about-images.sh'' script generates data about images by pattern:
+
''collect-info-about-images.sh'' スクリプトは、以下のパターンで画像に関するデータを生成します。
'''full path to image'''|'''Width'''|size|'''Height'''|size|'''Format'''|type of image|'''Errors'''|exit code by feh|
+
'''画像へのフルパス'''|''''''|サイズ|'''高さ'''|サイズ|'''フォーマット'''|画像の種類|'''エラー'''|feh による終了コード|
Example: {{ic|<nowiki>Images/f269351998.bmp|W|40|H|39|Format|bmp|Errors|0|</nowiki>}}
+
サンプル: {{ic|<nowiki>Images/f269351998.bmp|W|40|H|39|Format|bmp|Errors|0|</nowiki>}}
   
  +
== 解像度別に画像を整理する ==
== Sort images by resolution ==
 
  +
  +
このスクリプトは、解像度に基づいてフォルダを作成します。各フォルダにどれだけのファイルが含まれるべきか、基本のファイルタイプ名のフォルダにどれだけのサブディレクトリが含まれるべきかについて制限を設定できます。制限に達すると、新しい順序の番号がディレクトリ名に追加されて作成されます。非常に多くのファイルがある場合、すべてのファイルを1つのフォルダにオーバーロードしないように、基本の宛先変数 {{ic|1=IfExist="${Destination}/}} の後に、独自のカウンタを追加して新しいサブフォルダを作成することもできます。ただし、引用符 " が全体の宛先パスの始まりと終わりにあることに注意してください。画像の数が限られたフォルダを閲覧する方がはるかに簡単であり、サムネイルの読み込みがはるかに速くなり、お気に入りのフォルダ番号/名前を覚えて追加するのが簡単になります。
   
This script creates folders based on the resolution. You can set your limitations about how many files should be in each folder and how many sub-directories in a base file type named folder. When limit is reached a new number in the order will be added to a directory name for creation. If you have a really huge amount of files and do not want to overload a single folder with all of them then you can also add your own counters for a new sub-folders after the base destination variable {{ic|1=IfExist="${Destination}/}}, just look out for quotes " to be in the begin and end of a whole destination path. It use to be much more easier to browse folders with a limited amount of images, thumbnails loads much faster and to remember or add to favorite a folder number/name instead of trying to find once more same image in an overloaded folder out of probably thousand images there.
 
 
{{Warning|
 
{{Warning|
  +
* これらのスクリプトは例示的なものであり、使用する前にニーズに合わせて修正する必要があります。注意してください!
* Those script are only examples and you must modify them for your needs before using, be careful!
 
  +
* パスが正しく作成され、ソースファイルから変数を読み取る際に問題がないことを確認した後に、{{ic|echo}} コマンドを削除してください。特に {{ic|collect-info-about-images.sh }} ファイルに独自のオプションを追加して、画像に関するさらなる情報を収集、保存、使用する場合は注意してください。}}
* Remove the {{ic|echo}} command only after you confirmed that path are created correctly and no problems with reading variables out of a source file, specially in case if you added your own options into the {{ic|collect-info-about-images.sh }} file to gather, store and use even more information about images.}}
 
  +
 
{{Note|
 
{{Note|
* You must remove {{ic|echo}} command in front of {{ic|mkdir}} and {{ic|mv}}.
+
* {{ic|mkdir}} {{ic|mv}} の前の {{ic|echo}} コマンドを削除する必要があります。
  +
* 画面上の出力はスクリプトの動作を遅くします。さらに高速化するには、{{ic|-v}} オプションを削除して {{ic|mv}} と {{ic|cp}} の詳細出力を無効にします。
* Any output on screen slows script down, to make it even faster then disable verbose output for {{ic|mv}} and {{ic|cp}} by removing {{ic|-v}} option.
 
  +
* スクリプトが実行されていることを監視するには、CPU モニターユーティリティを使用して、宛先ディレクトリ内のフォルダをリストアップします。また、{{ic|echo}} コマンドを出力が最小限になるようなスクリプト部分にのみ追加することができます。例えば、フォルダ番号の更新など、時間の無限の感覚を避けるためにカウンタ部分です。
* To monitor that script is running you can use a CPU monitor utility and list folders in the destination directory. Or add {{ic|echo}} command only in those script parts where it will minimize output, e.g. counter part for updating of a folder number to avoid a time endless feeling.
 
  +
* また、{{ic|mv}} を {{ic|cp}} コマンドに置き換えて、ファイルをコピーする代わりに移動することもできます。}}
* You can also replace {{ic|mv}} with {{ic|cp}} command for copying of files instead of moving them.}}
 
 
{{bc|<nowiki>#!/bin/bash
 
{{bc|<nowiki>#!/bin/bash
   

2023年4月6日 (木) 17:13時点における最新版

関連記事

ノート: 回復されたり復元されたファイルへのアクセスを高速化するには、shake ユーティリティを使用してデフラグすることができます。

ファイルの回復が完了し、リカバリ後のタスクスクリプトの助けを借りて画像を復元したら、画像を解像度でソートすると良いでしょう。これにより、撮影した写真、ウェブカメラの画像、またはその他の画像を、解像度が同じ関連画像が多いフォルダにソートできます。

画像に関する情報を収集する

警告: スクリプトを実行する前に、feh プログラムをインストールしておく必要があります。
ノート: 画像に関する情報を収集する速度を上げるために、重複しないファイルのリストを使用して重複する画像をスキップできますが、このスクリプトでの mime タイプのチェックを削除し、代わりに拡張子でファイルをチェックするようにする必要があります。
collect-info-about-images.sh
#!/bin/bash
if [ 'XX' != 'XX'"$1" ]; then 
 if [ -f "$1"  ]; then
# mime part start
  IsIt=$(file "$1" --mime-type -b);
  NeedImageOnly="ItIs_"${IsIt/'/'*/}
   if [ "$NeedImageOnly" == "ItIs_image" ] ; then
# mime part end
ImageInfoFEH=($(feh -l "$1"))
IfDamaged=${?}
ImageType=${ImageInfoFEH[9]}
   Height=${ImageInfoFEH[11]}
    Width=${ImageInfoFEH[10]}
   if [ "$IfDamaged" != '0'  ]; then 
    echo "$1" "Damaged" "${IfDamaged}";
   fi;
    echo "$1"'|'W'|'$Width'|'H'|'$Height'|'Format'|'$ImageType'|'Errors'|'$IfDamaged'|' >> collect-info-about-images.txt
# mime part start
  fi
# mime part end
   else
    echo The « "$1" » is not a valid file name.
  fi
 else
  ScriptsName=${0##*/}
   find -type f -exec sh -e "./$ScriptsName" "{}" \;
  #find -type f  -name "*.jpg" -o -name "*.gif" -o -name "*.png" -exec sh -e "./$ScriptsName" "{}" \;
fi

$IfDamaged 変数は、feh によって返される終了ステータスコードを含みます。

ノート:
  • feh プログラムは、表示可能な視覚データが十分にある場合、画像の一部のエラー、ピクセルデータエラーを無視します。
  • ピクセルエラーにより、画像の一部または全体が正しく表示されず、誤った色や空白/空き領域が生じ、画像が多かれ少なかれ無用のものになることがよくあります。これは、画像内の破損したデータの量に大きく依存します。

また、pngcheckAUR をインストールして "PNG, JNG, MNG" の整合性をチェックし、および/または jpeginfoAUR をインストールし、$IfDamaged 変数のエラー出力を使用するか、破損したファイルを collect-info-about-images.txt ファイルに追加しないようにスクリプトを変更できます。

pngcheckAUR のチェック結果のサンプル:

./f939799496.png  invalid IDAT row-filter type (11)
./f939799496.png  private (invalid?) IDAT row-filter type (236) (warning)
./f939799496.png  private (invalid?) IDAT row-filter type (231) (warning)
./f939799496.png  invalid IDAT row-filter type (49)
./f939799496.png  zlib: inflate error = -3 (data error)
ERROR: ./f939799496.png
OK: ./f218842888.png (532x552, 32-bit RGB+alpha, non-interlaced, 95.8%).

jpeginfoAUR のチェック結果のサンプル:

f62152912.jpg 5678 x 2829 24bit Exif  N 11625509  Corrupt JPEG data: 1074 extraneous bytes before marker 0xd9  [WARNING]
f124619744.jpg  144 x 119  24bit JFIF  N    5813  [OK]
ノート: jpeginfoAUR ユーティリティはディレクトリを再帰的にスキャンできませんが、find -type f -name "*.jpg">>FileWithPathTo-images.txt で作成されたファイルからファイル名を読み取り、md5sum を計算し、破損した画像ファイルを削除するオプションがあります。

スクリプト内の文字列から必要なデータを抽出するには、sedgawk などの外部プログラムの代わりに、expressionを使用して、スクリプトの動作を少し高速化することが望ましいです。例えば、

AA="$(jpeginfo -c f62152912.jpg)";
ZZ="${AA/*' [OK]'/}"; 

if [ 'XX'"$ZZ" == 'XX' ]; then 
  echo File is good'!!!';
fi

collect-info-about-images.sh スクリプトは、以下のパターンで画像に関するデータを生成します。 画像へのフルパス||サイズ|高さ|サイズ|フォーマット|画像の種類|エラー|feh による終了コード| サンプル: Images/f269351998.bmp|W|40|H|39|Format|bmp|Errors|0|

解像度別に画像を整理する

このスクリプトは、解像度に基づいてフォルダを作成します。各フォルダにどれだけのファイルが含まれるべきか、基本のファイルタイプ名のフォルダにどれだけのサブディレクトリが含まれるべきかについて制限を設定できます。制限に達すると、新しい順序の番号がディレクトリ名に追加されて作成されます。非常に多くのファイルがある場合、すべてのファイルを1つのフォルダにオーバーロードしないように、基本の宛先変数 IfExist="${Destination}/ の後に、独自のカウンタを追加して新しいサブフォルダを作成することもできます。ただし、引用符 " が全体の宛先パスの始まりと終わりにあることに注意してください。画像の数が限られたフォルダを閲覧する方がはるかに簡単であり、サムネイルの読み込みがはるかに速くなり、お気に入りのフォルダ番号/名前を覚えて追加するのが簡単になります。

警告:
  • これらのスクリプトは例示的なものであり、使用する前にニーズに合わせて修正する必要があります。注意してください!
  • パスが正しく作成され、ソースファイルから変数を読み取る際に問題がないことを確認した後に、echo コマンドを削除してください。特に collect-info-about-images.sh ファイルに独自のオプションを追加して、画像に関するさらなる情報を収集、保存、使用する場合は注意してください。
ノート:
  • mkdirmv の前の echo コマンドを削除する必要があります。
  • 画面上の出力はスクリプトの動作を遅くします。さらに高速化するには、-v オプションを削除して mvcp の詳細出力を無効にします。
  • スクリプトが実行されていることを監視するには、CPU モニターユーティリティを使用して、宛先ディレクトリ内のフォルダをリストアップします。また、echo コマンドを出力が最小限になるようなスクリプト部分にのみ追加することができます。例えば、フォルダ番号の更新など、時間の無限の感覚を避けるためにカウンタ部分です。
  • また、mvcp コマンドに置き換えて、ファイルをコピーする代わりに移動することもできます。
#!/bin/bash

NumberOfBaseDir="0"
SubDirNumber="0"
CountAll="0"
NumDir="0"

echo Creating destination.
Destination="./SortedImages"
echo mkdir -v "${Destination}" -p 
echo Created destination with status: $?

echo Your set of limitations.
SDN=50; echo Limit files in a subdir: $SDN
NBD=50; echo Limit subdirs in a file type named destination: $NBD

SourceDataFile="collect-info-about-images.txt"
echo Source file with a necessery data: $SourceDataFile

if [ 'XX' == 'XX'"$SourceDataFile" ] ; then 
 echo The '$SourceDataFile' variable is empty
 exit 1
else 
 if [ ! -f "$SourceDataFile" ]; then 
  echo The "$SourceDataFile" file doesn"'"t exist
  exit 2
 fi;
fi;

echo Populating an array from a file
ArrayFillCount=0;
while read line ; do
  tmpWb="${line/|H|*/}";
W="${tmpWb/*W|/}";
  tmpHb="${line/|Format|*/}";
H="${tmpHb/*|/}";

#if (( "$W" >= "800" )) && (( "$W" <=  "1000" )); then
#if (( "$H" >= "800" )) && (( "$H" <=  "1000" )); then
  ArrayOfFiles[$ArrayFillCount]="$line";
  ArrayFillCount=$((ArrayFillCount+1))
DupLimitKeeper[$W,$H]="0";
#fi;fi;

done < $SourceDataFile;
echo Done with extracting of necessary data about resolutions.

echo Starting loop of restoration
XX=${#ArrayOfFiles[@]}
while [  "${XX}" != "${CountAl}l" ] ; do
  preType=${ArrayOfFiles[$CountAll]/*"|Format|"/};
ImageType=${preType/|*/}
  preW=${ArrayOfFiles[$CountAll]/*"|W|"/};Width=${preW/|*/};preH=${ArrayOfFiles[$CountAll]/*"|H|"/} 
Height=${preH/|*/};
PathToFile=${ArrayOfFiles[$CountAll]/"|"*/}

DupLimitKeeper[Width,Height]=$((DupLimitKeeper[Width,Height]+1));

IfExist="${Destination}/${ImageType}${NumberOfBaseDir}/Resolution_${Width}x${Height}_DirN${SubDirNumber}"

if [ ! -d "$IfExist"  ];then 
  echo mkdir -vp "$IfExist"
NumDir=$((NumDir+1));
fi

## Creating a new numbered file type folders
if [ "${DupLimitKeeper[Width,Height]}" -gt $SDN ]; then 
  SubDirNumber=$((SubDirNumber+1));
  DupLimitKeeper[$Width,$Height]="0";
fi

## Adding a file number 
FileNameOnly="${PathToFile##*/}"
NewFileName="N${CountAll}C${FileNameOnly}"
#NewFileName="${FileNameOnly}"

## Creating a new sub-dir when limit of files in a sub-folder is reached
if [ $NumDir -gt $NBD ];then 
  NumberOfBaseDir=$((NumberOfBaseDir+1));
  NumDir="0";
fi
##
if [ -f "${PathToFile}" ];then
  echo mv -v "${PathToFile}" "$IfExist/$NewFileName";
# echo cp -v "${PathToFile}" "$IfExist/$NewFileName";
fi

CountAll=$((CountAll+1)) 
done
echo Total processed files: $CountAll

See also