LibreOfficeのファイルサイズを削減

某所のコミケの原稿、LibreOfficeのファイルサイズが大きいということで、ファイルサイズの削減にチャレンジ。


```

$  ls -alh
合計 9.5M
drwxrwxr-x   3 nanbuwks nanbuwks 4.0K  8月  1 10:45 .
drwxr-xr-x 118 nanbuwks nanbuwks 104K  8月  1 10:29 ..
-rw-rw-r--   1 nanbuwks nanbuwks 5.6M  8月  1 10:28 C93test.odt
```

ふむ、まずは中身を見てみる。


```

$ mkdir dist
$ cd dist
$ unzip ../C93test.odt
Archive:  ../C93test.odt
 extracting: mimetype                
 extracting: Thumbnails/thumbnail.png  
  inflating: layout-cache            
   creating: Configurations2/floater/
   creating: Configurations2/toolbar/
   creating: Configurations2/images/Bitmaps/
  inflating: Configurations2/accelerator/current.xml  
   creating: Configurations2/progressbar/
   creating: Configurations2/popupmenu/
   creating: Configurations2/statusbar/
   creating: Configurations2/menubar/
   creating: Configurations2/toolpanel/
  inflating: content.xml             
  inflating: meta.xml                
  inflating: manifest.rdf            
  inflating: settings.xml            
  inflating: styles.xml              
 extracting: Pictures/10000000000003B2000002663104167F68DF6931.jpg  
 extracting: Pictures/100002010000001000000010F9970A9B446EDA8D.png  
 extracting: Pictures/10000000000002020000016E3600C0D6E217BD91.jpg  
 extracting: Pictures/100000000000020800000172724EB8809F1FB5E8.jpg  
 extracting: Pictures/1000000000000306000002889ECB54087B847EE7.jpg  
 extracting: Pictures/10000000000002F80000021E8684805ECC07B8F4.jpg  
 extracting: Pictures/1000000000000150000000EE6B4B38DC6F45FB07.jpg  
 extracting: Pictures/1000000000000150000000EECB8BDCE8E44F7A2D.jpg  
 extracting: Pictures/10000000000003D2000003AAE1ACA9292B9BD2E3.jpg  
 extracting: Pictures/10000000000001F800000165E17A3CA73825602E.jpg  
 extracting: Pictures/1000000000000320000002584128EEF77C2053F9.jpg  
 extracting: Pictures/10000201000004F5000003EA0A79E4D769A6CBDD.png  
 extracting: Pictures/10000000000007080000055D5023CFB285A0CF0E.jpg  
 extracting: Pictures/10000000000001F8000001519A2880DA5F5CB1F7.jpg  
 extracting: Pictures/1000000000000150000000EE870A56D4158FD0E8.jpg  
 extracting: Pictures/10000000000004000000030038FC945FAB091CF0.jpg  
 extracting: Pictures/1000020100000256000002007E798D179AD4DB6E.png  
 extracting: Pictures/100002010000049E000003F688FE32D1FDD8D97B.png  
 extracting: Pictures/10000201000006750000048DFE72C1A096127FDB.png  
 extracting: Pictures/10000201000002AA0000021C90B1BD1A4366DF7E.png  
 extracting: Pictures/1000000000000150000000EE33E962F39832582F.jpg  
 extracting: Pictures/10000201000002BA000001A7EBD8C3B7DA0C9C18.png  
 extracting: Pictures/1000000000000150000000EEC572001EE8951894.jpg  
 extracting: Pictures/100000000000022D000001C6AC7FBA43E9A2DA73.jpg  
 extracting: Pictures/1000000000000140000000BE7036A9D9E0BF77B3.jpg  
 extracting: Pictures/1000000000000008000000083379E409CE935A89.png  
 extracting: Pictures/100000000000020E00000176D3C3B9FDB56BE940.jpg  
 extracting: Pictures/10000000000001D200000163A8B99FBCBCB934AC.jpg  
  inflating: META-INF/manifest.xml

```

まあ、作業すべきはPicturesでしょう。

```

$ cd Pictures/
$ ls -alh
合計 5.6M
drwxrwxr-x 2 nanbuwks nanbuwks 4.0K  8月  1 10:43 .
drwxrwxr-x 6 nanbuwks nanbuwks 4.0K  8月  1 10:43 ..
-rw-rw-r-- 1 nanbuwks nanbuwks   69  7月 31 08:34 1000000000000008000000083379E409CE935A89.png
-rw-rw-r-- 1 nanbuwks nanbuwks  18K  7月 31 08:34 1000000000000140000000BE7036A9D9E0BF77B3.jpg
-rw-rw-r-- 1 nanbuwks nanbuwks  23K  7月 31 08:34 1000000000000150000000EE33E962F39832582F.jpg
-rw-rw-r-- 1 nanbuwks nanbuwks  18K  7月 31 08:34 1000000000000150000000EE6B4B38DC6F45FB07.jpg
-rw-rw-r-- 1 nanbuwks nanbuwks  21K  7月 31 08:34 1000000000000150000000EE870A56D4158FD0E8.jpg
-rw-rw-r-- 1 nanbuwks nanbuwks  16K  7月 31 08:34 1000000000000150000000EEC572001EE8951894.jpg
-rw-rw-r-- 1 nanbuwks nanbuwks  20K  7月 31 08:34 1000000000000150000000EECB8BDCE8E44F7A2D.jpg
-rw-rw-r-- 1 nanbuwks nanbuwks  88K  7月 31 08:34 10000000000001D200000163A8B99FBCBCB934AC.jpg
-rw-rw-r-- 1 nanbuwks nanbuwks  87K  7月 31 08:34 10000000000001F8000001519A2880DA5F5CB1F7.jpg
-rw-rw-r-- 1 nanbuwks nanbuwks  34K  7月 31 08:34 10000000000001F800000165E17A3CA73825602E.jpg
-rw-rw-r-- 1 nanbuwks nanbuwks  39K  7月 31 08:34 10000000000002020000016E3600C0D6E217BD91.jpg
-rw-rw-r-- 1 nanbuwks nanbuwks  59K  7月 31 08:34 100000000000020800000172724EB8809F1FB5E8.jpg
-rw-rw-r-- 1 nanbuwks nanbuwks  46K  7月 31 08:34 100000000000020E00000176D3C3B9FDB56BE940.jpg
-rw-rw-r-- 1 nanbuwks nanbuwks  91K  7月 31 08:34 100000000000022D000001C6AC7FBA43E9A2DA73.jpg
-rw-rw-r-- 1 nanbuwks nanbuwks  42K  7月 31 08:34 10000000000002F80000021E8684805ECC07B8F4.jpg
-rw-rw-r-- 1 nanbuwks nanbuwks  94K  7月 31 08:34 1000000000000306000002889ECB54087B847EE7.jpg
-rw-rw-r-- 1 nanbuwks nanbuwks 465K  7月 31 08:34 1000000000000320000002584128EEF77C2053F9.jpg
-rw-rw-r-- 1 nanbuwks nanbuwks  70K  7月 31 08:34 10000000000003B2000002663104167F68DF6931.jpg
-rw-rw-r-- 1 nanbuwks nanbuwks 254K  7月 31 08:34 10000000000003D2000003AAE1ACA9292B9BD2E3.jpg
-rw-rw-r-- 1 nanbuwks nanbuwks 110K  7月 31 08:34 10000000000004000000030038FC945FAB091CF0.jpg
-rw-rw-r-- 1 nanbuwks nanbuwks 1.2M  7月 31 08:34 10000000000007080000055D5023CFB285A0CF0E.jpg
-rw-rw-r-- 1 nanbuwks nanbuwks  687  7月 31 08:34 100002010000001000000010F9970A9B446EDA8D.png
-rw-rw-r-- 1 nanbuwks nanbuwks  34K  7月 31 08:34 1000020100000256000002007E798D179AD4DB6E.png
-rw-rw-r-- 1 nanbuwks nanbuwks  67K  7月 31 08:34 10000201000002AA0000021C90B1BD1A4366DF7E.png
-rw-rw-r-- 1 nanbuwks nanbuwks  58K  7月 31 08:34 10000201000002BA000001A7EBD8C3B7DA0C9C18.png
-rw-rw-r-- 1 nanbuwks nanbuwks 257K  7月 31 08:34 100002010000049E000003F688FE32D1FDD8D97B.png
-rw-rw-r-- 1 nanbuwks nanbuwks 790K  7月 31 08:34 10000201000004F5000003EA0A79E4D769A6CBDD.png
-rw-rw-r-- 1 nanbuwks nanbuwks 1.7M  7月 31 08:34 10000201000006750000048DFE72C1A096127FDB.png

```

1.2Mのと1.7Mの画像ファイルがありますね。最後の1.7Mのファイルをターゲットにしてみます。

このファイルは何の画像かな？

```

$ display 10000201000006750000048DFE72C1A096127FDB.png 

```
![image](https://qiita-image-store.s3.amazonaws.com/0/139524/0ba8d6cd-d4a8-2066-7f5e-009b13be6725.png)

画像の大きさはどれくらいだろう？

```

$ identify -format "%w %h" 10000201000006750000048DFE72C1A096127FDB.png 
1653 1165
```

ふむふむ。この画像がどこに使われているのかな？

```

$ libreoffice ../../C93test.odt
```

![image](https://qiita-image-store.s3.amazonaws.com/0/139524/2b30b683-33dc-6164-37f5-667728acc02f.png)

小さい扱いなので、画像サイズはもっと小さくてもいいですね。

```

$ mogrify -resize 300 10000201000006750000048DFE72C1A096127FDB.png 
$ ls -alh 10000201000006750000048DFE72C1A096127FDB.png 
-rw-rw-r-- 1 nanbuwks nanbuwks 91K  8月  1 10:44 10000201000006750000048DFE72C1A096127FDB.png

```
小さくなったよ！


1.2Mのファイルについても同様に作業してから、


```

$ cd ..
$ zip -r ../C93test2.odt *
updating: Configurations2/ (stored 0%)
updating: Configurations2/accelerator/ (stored 0%)
updating: Configurations2/accelerator/current.xml (stored 0%)
updating: Configurations2/progressbar/ (stored 0%)
updating: Configurations2/toolpanel/ (stored 0%)
updating: Configurations2/floater/ (stored 0%)
updating: Configurations2/images/ (stored 0%)
updating: Configurations2/images/Bitmaps/ (stored 0%)
updating: Configurations2/menubar/ (stored 0%)
updating: Configurations2/toolbar/ (stored 0%)
updating: Configurations2/popupmenu/ (stored 0%)
updating: Configurations2/statusbar/ (stored 0%)
updating: META-INF/ (stored 0%)
updating: META-INF/manifest.xml (deflated 82%)
updating: Pictures/ (stored 0%)
updating: Pictures/100002010000001000000010F9970A9B446EDA8D.png (stored 0%)
updating: Pictures/10000201000002AA0000021C90B1BD1A4366DF7E.png (deflated 9%)
updating: Pictures/10000000000001D200000163A8B99FBCBCB934AC.jpg (deflated 1%)
updating: Pictures/10000201000002BA000001A7EBD8C3B7DA0C9C18.png (deflated 5%)
updating: Pictures/10000000000004000000030038FC945FAB091CF0.jpg (deflated 0%)
updating: Pictures/1000000000000150000000EE870A56D4158FD0E8.jpg (deflated 1%)
updating: Pictures/10000201000006750000048DFE72C1A096127FDB.png (deflated 0%)
updating: Pictures/10000000000003B2000002663104167F68DF6931.jpg (deflated 10%)
updating: Pictures/1000020100000256000002007E798D179AD4DB6E.png (deflated 9%)
updating: Pictures/100000000000022D000001C6AC7FBA43E9A2DA73.jpg (deflated 0%)
updating: Pictures/1000000000000150000000EE33E962F39832582F.jpg (deflated 1%)
updating: Pictures/1000000000000008000000083379E409CE935A89.png (deflated 9%)
updating: Pictures/10000000000001F800000165E17A3CA73825602E.jpg (deflated 1%)
updating: Pictures/1000000000000320000002584128EEF77C2053F9.jpg (deflated 3%)
updating: Pictures/10000000000003D2000003AAE1ACA9292B9BD2E3.jpg (deflated 0%)
updating: Pictures/10000201000004F5000003EA0A79E4D769A6CBDD.png (deflated 1%)
updating: Pictures/100002010000049E000003F688FE32D1FDD8D97B.png (deflated 6%)
updating: Pictures/10000000000002020000016E3600C0D6E217BD91.jpg (deflated 3%)
updating: Pictures/1000000000000140000000BE7036A9D9E0BF77B3.jpg (deflated 6%)
updating: Pictures/1000000000000150000000EECB8BDCE8E44F7A2D.jpg (deflated 1%)
updating: Pictures/10000000000002F80000021E8684805ECC07B8F4.jpg (deflated 6%)
updating: Pictures/1000000000000150000000EE6B4B38DC6F45FB07.jpg (deflated 1%)
updating: Pictures/10000000000007080000055D5023CFB285A0CF0E.jpg (deflated 13%)
updating: Pictures/10000000000001F8000001519A2880DA5F5CB1F7.jpg (deflated 18%)
updating: Pictures/100000000000020800000172724EB8809F1FB5E8.jpg (deflated 2%)
updating: Pictures/100000000000020E00000176D3C3B9FDB56BE940.jpg (deflated 2%)
updating: Pictures/1000000000000306000002889ECB54087B847EE7.jpg (deflated 4%)
updating: Pictures/1000000000000150000000EEC572001EE8951894.jpg (deflated 2%)
updating: Thumbnails/ (stored 0%)
updating: Thumbnails/thumbnail.png (deflated 0%)
updating: content.xml (deflated 82%)
updating: layout-cache (deflated 57%)
updating: manifest.rdf (deflated 71%)
updating: meta.xml (deflated 53%)
updating: mimetype (stored 0%)
updating: settings.xml (deflated 85%)
updating: styles.xml (deflated 88%)
```

としてファイルを作りなおしました。

```

$ cd ..
$ ls -alh 
合計 8.6M
drwxrwxr-x   3 nanbuwks nanbuwks 4.0K  8月  1 10:51 .
drwxr-xr-x 118 nanbuwks nanbuwks 104K  8月  1 10:29 ..
-rw-rw-r--   1 nanbuwks nanbuwks 5.6M  8月  1 10:28 C93test.odt
-rw-rw-r--   1 nanbuwks nanbuwks 2.9M  8月  1 10:51 C93test2.odt
drwxrwxr-x   6 nanbuwks nanbuwks 4.0K  8月  1 10:43 dist
```

半分ぐらいに小さくなりました。

```

$ libreoffice C93test2.odt 
```
できたものを確認して、問題なければ終了です。