0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

RubyでPNGにLibreOffice Drawのodgファイルを埋め込んで再編集可能にする

Last updated at Posted at 2025-12-26

これは LibreOffice Advent Calendar 2025 の24日目の記事です。


以下の nanbuwks さんの記事で LibreOffice Draw の odg ファイルを png ファイルに埋め込み再編集可能にする試みが紹介されています。

私も以前から似たようなことを考えていたのでたいへん参考になりました。上記の記事を参考に Ruby で書いてみました。

スクリプト

基本操作である埋め込みと抽出だけを行うスクリプトです。png ファイルのメタデータの読み書きには chunky_png gem を使いました。

png_odg.rb:

実行の例

ruby -v
  #=> ruby 4.0.0 (2025-12-25 revision 553f1675f3) +PRISM [x86_64-linux]

  # img.png に test.odg を埋め込む
ruby png_odg.rb embed img.png test.odg
  #=> img.odg.png が生成される

  # img.odg.png から odg ファイルを抽出する
ruby png_odg.rb extract img.odg.png test2.odg
  #=> test2.odg が生成される

md5sum test.odg test2.odg
  # 8b2819a45a3c83f314841f33a9b1d302  test.odg
  # 8b2819a45a3c83f314841f33a9b1d302  test2.odg
  # 抽出された odg ファイルは元のファイルと同一

とりあえず元のファイルは上書きせず新しいファイルを生成する動作にしています。

この記事を読んだ人は(ひょっとしたら)こちらも読んでいます

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?