{"componentChunkName":"component---src-templates-post-template-js","path":"/posts/image-file-format-basics","result":{"data":{"markdownRemark":{"id":"2651712b-8f4c-58bb-a3e2-c2e813ceb2fd","html":"<p><a href=\"https://qiita.com/advent-calendar/2021/media-and-xr-lonely\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">画像・動画・音声処理および XR 一人アドベントカレンダー</a> 2 日目の記事です。</p>\n<h2 id=\"はじめに\" style=\"position:relative;\"><a href=\"#%E3%81%AF%E3%81%98%E3%82%81%E3%81%AB\" aria-label=\"はじめに permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>はじめに</h2>\n<p>画像ファイルフォーマットの基本について調べたことをまとめます。</p>\n<h2 id=\"画像ファイルフォーマットの分類\" style=\"position:relative;\"><a href=\"#%E7%94%BB%E5%83%8F%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%83%95%E3%82%A9%E3%83%BC%E3%83%9E%E3%83%83%E3%83%88%E3%81%AE%E5%88%86%E9%A1%9E\" aria-label=\"画像ファイルフォーマットの分類 permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>画像ファイルフォーマットの分類</h2>\n<p>画像ファイルフォーマットについては、Wikipedia の以下の 4 つの記事がとっかかりとして良いです。</p>\n<ul>\n<li><a href=\"https://ja.wikipedia.org/wiki/%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%83%95%E3%82%A9%E3%83%BC%E3%83%9E%E3%83%83%E3%83%88\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">ファイルフォーマット - Wikipedia</a></li>\n<li><a href=\"https://ja.wikipedia.org/wiki/%E7%94%BB%E5%83%8F%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%83%95%E3%82%A9%E3%83%BC%E3%83%9E%E3%83%83%E3%83%88%E3%81%AE%E6%AF%94%E8%BC%83\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">画像ファイルフォーマットの比較 - Wikipedia</a></li>\n<li><a href=\"https://ja.wikipedia.org/wiki/%E3%83%93%E3%83%83%E3%83%88%E3%83%9E%E3%83%83%E3%83%97%E7%94%BB%E5%83%8F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">ビットマップ画像 - Wikipedia</a></li>\n<li><a href=\"https://ja.wikipedia.org/wiki/%E3%83%99%E3%82%AF%E3%82%BF%E3%83%BC%E7%94%BB%E5%83%8F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">ベクター画像 - Wikipedia</a></li>\n</ul>\n<p>最近よく見る画像ファイルフォーマットを分類すると、以下のようになります。</p>\n<ul>\n<li>\n<p>ビットマップ画像 (ラスター形式)</p>\n<ul>\n<li>PNG</li>\n<li>JPEG</li>\n<li>GIF</li>\n<li>WebP</li>\n</ul>\n</li>\n<li>\n<p>ベクター画像 (ベクター形式)</p>\n<ul>\n<li>SVG</li>\n</ul>\n</li>\n<li>\n<p>その他、一緒に知っておきたいファイルフォーマット</p>\n<ul>\n<li>PDF</li>\n</ul>\n</li>\n</ul>\n<p>順に概要を見ていきます。</p>\n<h2 id=\"ビットマップ画像-ラスター形式\" style=\"position:relative;\"><a href=\"#%E3%83%93%E3%83%83%E3%83%88%E3%83%9E%E3%83%83%E3%83%97%E7%94%BB%E5%83%8F-%E3%83%A9%E3%82%B9%E3%82%BF%E3%83%BC%E5%BD%A2%E5%BC%8F\" aria-label=\"ビットマップ画像 ラスター形式 permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>ビットマップ画像 (ラスター形式)</h2>\n<p>ピクセル単位で色の情報を持っているのがビットマップ画像です。</p>\n<p>PNG・JPEG・GIF の比較については、以下の記事が参考になります。</p>\n<ul>\n<li><a href=\"http://www.htmq.com/gazo/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">WEB 画像について－GIF・JPEG・PNG の特徴</a></li>\n<li><a href=\"https://time-space.kddi.com/ict-keywords/kaisetsu/20160627/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">JPEG、GIF、PNG、なんて読む？ 『画像ファイルの拡張子』の違い｜ TIME＆SPACE by KDDI</a></li>\n<li><a href=\"https://note.cman.jp/picture/jpeg_png_gif/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">「JPEG（JPG）」,「PNG」,「GIF」の違い</a></li>\n</ul>\n<h3 id=\"png-portable-network-graphics\" style=\"position:relative;\"><a href=\"#png-portable-network-graphics\" aria-label=\"png portable network graphics permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>PNG (Portable Network Graphics)</h3>\n<p>特徴</p>\n<ul>\n<li>基本的にフルカラー (24 bit)</li>\n<li>可逆圧縮</li>\n</ul>\n<p>なお、「<a href=\"https://ja.wikipedia.org/wiki/%E3%83%95%E3%83%AB%E3%82%AB%E3%83%A9%E3%83%BC\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">フルカラー - Wikipedia</a>」によると、24 bit カラーをフルカラーと呼ぶことが多いとのことです。</p>\n<blockquote>\n<p>24 ビットカラー（16,777,216 色）、トゥルーカラー（truecolor, true colors）。(中略) 現代のパソコン業界では、トゥルーカラーのみをフルカラーと呼ぶことが多い。</p>\n</blockquote>\n<h3 id=\"jpeg-joint-photographic-experts-group\" style=\"position:relative;\"><a href=\"#jpeg-joint-photographic-experts-group\" aria-label=\"jpeg joint photographic experts group permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>JPEG (Joint Photographic Experts Group)</h3>\n<p>特徴</p>\n<ul>\n<li>フルカラー (24 bit)</li>\n<li>基本的に非可逆圧縮</li>\n</ul>\n<h3 id=\"gif-graphics-interchange-format\" style=\"position:relative;\"><a href=\"#gif-graphics-interchange-format\" aria-label=\"gif graphics interchange format permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>GIF (Graphics Interchange Format)</h3>\n<p>特徴</p>\n<ul>\n<li>256 色 (8 bit)</li>\n<li>可逆圧縮</li>\n<li>アニメーションをサポート</li>\n</ul>\n<h3 id=\"webp-ウェッピー\" style=\"position:relative;\"><a href=\"#webp-%E3%82%A6%E3%82%A7%E3%83%83%E3%83%94%E3%83%BC\" aria-label=\"webp ウェッピー permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>WebP (ウェッピー)</h3>\n<p>WebP は、Google が開発した圧縮率の高い画像形式です。</p>\n<p>特徴</p>\n<ul>\n<li>可逆圧縮・非可逆圧縮</li>\n</ul>\n<p>参考: <a href=\"https://www.sedesign.co.jp/blog/what-is-the-difference-between-webp-and-others\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">WebP とその他画像形式の違いとは？3 つのメリットと変換方法解説</a></p>\n<h2 id=\"ベクター画像-ベクター形式\" style=\"position:relative;\"><a href=\"#%E3%83%99%E3%82%AF%E3%82%BF%E3%83%BC%E7%94%BB%E5%83%8F-%E3%83%99%E3%82%AF%E3%82%BF%E3%83%BC%E5%BD%A2%E5%BC%8F\" aria-label=\"ベクター画像 ベクター形式 permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>ベクター画像 (ベクター形式)</h2>\n<p>画像を幾何学的な図形として表現するのがベクター形式です。</p>\n<h3 id=\"svg-scalable-vector-graphics\" style=\"position:relative;\"><a href=\"#svg-scalable-vector-graphics\" aria-label=\"svg scalable vector graphics permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>SVG (Scalable Vector Graphics)</h3>\n<p>ベクター画像と言えば SVG だと思います。</p>\n<p>SVG は、XML ベースのベクター画像形式です。</p>\n<h2 id=\"その他、一緒に知っておきたいファイルフォーマット\" style=\"position:relative;\"><a href=\"#%E3%81%9D%E3%81%AE%E4%BB%96%E3%80%81%E4%B8%80%E7%B7%92%E3%81%AB%E7%9F%A5%E3%81%A3%E3%81%A6%E3%81%8A%E3%81%8D%E3%81%9F%E3%81%84%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%83%95%E3%82%A9%E3%83%BC%E3%83%9E%E3%83%83%E3%83%88\" aria-label=\"その他、一緒に知っておきたいファイルフォーマット permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>その他、一緒に知っておきたいファイルフォーマット</h2>\n<h3 id=\"pdf-portable-document-format\" style=\"position:relative;\"><a href=\"#pdf-portable-document-format\" aria-label=\"pdf portable document format permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>PDF (Portable Document Format)</h3>\n<p>PDF は、Adobe が開発した文書フォーマットです。</p>\n<p>現在は ISO 32000-1 として標準化されています。</p>\n<p>PDF 自体は画像ではないです (画像に分類されているケースもあります) が、内部にベクター画像やラスター画像を保持することもできます。</p>\n<p>参考: <a href=\"https://ja.wikipedia.org/wiki/Portable_Document_Format\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Portable Document Format - Wikipedia</a></p>\n<h2 id=\"画像ファイルをよく見てみる\" style=\"position:relative;\"><a href=\"#%E7%94%BB%E5%83%8F%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%82%92%E3%82%88%E3%81%8F%E8%A6%8B%E3%81%A6%E3%81%BF%E3%82%8B\" aria-label=\"画像ファイルをよく見てみる permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>画像ファイルをよく見てみる</h2>\n<p>さて、これだけで終わっては面白くないので、画像ファイルをよく見てみたりしようと思います。</p>\n<h3 id=\"png\" style=\"position:relative;\"><a href=\"#png\" aria-label=\"png permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>PNG</h3>\n<p>「<a href=\"https://en.wikipedia.org/wiki/File:Lenna_(test_image).png\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">File:Lenna (test image).png - Wikipedia</a>」からレナ画像を取得します。</p>\n<div class=\"gatsby-highlight\" data-language=\"console\"><pre class=\"language-console\"><code class=\"language-console\">curl https://upload.wikimedia.org/wikipedia/en/7/7d/Lenna_%28test_image%29.png &gt; Lenna.png</code></pre></div>\n<p>hexdump で見てみると、以下のようになります。</p>\n<div class=\"gatsby-highlight\" data-language=\"console\"><pre class=\"language-console\"><code class=\"language-console\">$ hexdump -C Lenna.png | head\n00000000  89 50 4e 47 0d 0a 1a 0a  00 00 00 0d 49 48 44 52  |.PNG........IHDR|\n00000010  00 00 02 00 00 00 02 00  08 02 00 00 00 7b 1a 43  |.............{.C|\n00000020  ad 00 00 00 01 73 52 47  42 00 ae ce 1c e9 00 07  |.....sRGB.......|\n00000030  3a a1 49 44 41 54 78 da  ec e1 5d 92 6d 5b 92 1d  |:.IDATx...].m[..|\n00000040  e6 8d e1 ee 73 ae b5 23  e2 9c 7b 33 ab 20 08 e4  |....s..#..{3. ..|\n00000050  8b 5a 20 a3 8c 46 51 a4  f1 4f 25 a3 99 3a 23 a3  |.Z ..FQ..O%..:#.|\n00000060  00 ea 55 0d 50 e3 d4 00  51 a4 c1 00 92 48 20 ab  |..U.P...Q....H .|\n00000070  b2 f2 de 7b 22 f6 5e 6b  4e 77 1f 4a b5 03 f9 7d  |...{&quot;.^kNw.J...}|\n00000080  fc d7 ff af ff 27 80 c2  09 6d b7 0b af b4 c7 a1  |.....&#39;...m......|\n00000090  24 a6 77 5e ae a3 b4 3b  7f f8 e3 bd 92 bd 16 c6  |$.w^...;........|</code></pre></div>\n<p>「<a href=\"https://ja.wikipedia.org/wiki/Portable_Network_Graphics\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Portable Network Graphics - Wikipedia</a>」によると PNG の先頭 8 バイトは</p>\n<blockquote>\n<p>「89 50 4E 47 0D 0A 1A 0A」</p>\n</blockquote>\n<p>とのことですが、確かにその通りになっています。</p>\n<p>なお、「<a href=\"https://qiita.com/urakarin/items/337a0433a41443731ad0\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">vim でバイナリを編集する - Qiita</a>」という記事を参考に、<code class=\"language-text\">vim -b</code> と <code class=\"language-text\">:%!xdd</code> でバイナリを見てみると、最初の 10 行は以下のようになります。</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">00000000: 8950 4e47 0d0a 1a0a 0000 000d 4948 4452  .PNG........IHDR\n00000010: 0000 0200 0000 0200 0802 0000 007b 1a43  .............{.C\n00000020: ad00 0000 0173 5247 4200 aece 1ce9 0007  .....sRGB.......\n00000030: 3aa1 4944 4154 78da ece1 5d92 6d5b 921d  :.IDATx...].m[..\n00000040: e68d e1ee 73ae b523 e29c 7b33 ab20 08e4  ....s..#..{3. ..\n00000050: 8b5a 20a3 8c46 51a4 f14f 25a3 993a 23a3  .Z ..FQ..O%..:#.\n00000060: 00ea 550d 50e3 d400 51a4 c100 9248 20ab  ..U.P...Q....H .\n00000070: b2f2 de7b 22f6 5e6b 4e77 1f4a b503 f97d  ...{&quot;.^kNw.J...}\n00000080: fcd7 ffaf ff27 80c2 096d b70b afb4 c7a1  .....&#39;...m......\n00000090: 24a6 775e aea3 b43b 7ff8 e3bd 92bd 16c6  $.w^...;........</code></pre></div>\n<p>PNG のバイナリを Vim などで編集するのは、圧縮されていたりするためとても難しいです。</p>\n<p>Python の Pillow などのライブラリを使うと 8bit ずつの RGB などを簡単に取得できたり編集できたりしますが、内部で色んなことをやってくれているんだなと実感します。</p>\n<p>そのあたりについて、以下の記事は自前でいろいろ処理していてとても面白いです。</p>\n<ul>\n<li><a href=\"https://qiita.com/kouheiszk/items/17485ccb902e8190923b\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">PNG を読む - Qiita</a></li>\n</ul>\n<h3 id=\"svg\" style=\"position:relative;\"><a href=\"#svg\" aria-label=\"svg permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>SVG</h3>\n<p>「<a href=\"https://www.tohoho-web.com/ex/svg.html\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">SVG 入門 - とほほの WWW 入門</a>」を参考に、ちょっとした SVG ファイルを作ってみます。</p>\n<p>SVG はただのテキストファイルなので、エディタで作ることも可能です。</p>\n<p>以下のような SVG ファイルを作成すると…</p>\n<div class=\"gatsby-highlight\" data-language=\"svg\"><pre class=\"language-svg\"><code class=\"language-svg\"><span class=\"token prolog\">&lt;?xml version=\"1.0\"?></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>svg</span> <span class=\"token attr-name\">xmlns</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>http://www.w3.org/2000/svg<span class=\"token punctuation\">\"</span></span> <span class=\"token attr-name\">x</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>0<span class=\"token punctuation\">\"</span></span> <span class=\"token attr-name\">y</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>0<span class=\"token punctuation\">\"</span></span> <span class=\"token attr-name\">width</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>200<span class=\"token punctuation\">\"</span></span> <span class=\"token attr-name\">height</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>200<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span>\n  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>circle</span> <span class=\"token attr-name\">cx</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>100<span class=\"token punctuation\">\"</span></span> <span class=\"token attr-name\">cy</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>100<span class=\"token punctuation\">\"</span></span> <span class=\"token attr-name\">r</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>100<span class=\"token punctuation\">\"</span></span> <span class=\"token attr-name\">stroke</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>black<span class=\"token punctuation\">\"</span></span> <span class=\"token attr-name\">fill</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>#fff<span class=\"token punctuation\">\"</span></span> <span class=\"token attr-name\">stroke-width</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>1<span class=\"token punctuation\">\"</span></span> <span class=\"token punctuation\">/></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>svg</span><span class=\"token punctuation\">></span></span></code></pre></div>\n<p><img src=\"/media/svg_circle.svg\" alt=\"svg_circle.svg\"></p>\n<p>円が表示されました。</p>\n<h3 id=\"pdf\" style=\"position:relative;\"><a href=\"#pdf\" aria-label=\"pdf permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>PDF</h3>\n<p>最後に、PDF のファイルフォーマットについて面白い記事をいくつか見かけたので、リンクを貼っておきます。</p>\n<ul>\n<li><a href=\"https://techracho.bpsinc.jp/west/2018_12_07/65062\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">見て作って学ぶ、PDF ファイルの基本構造｜ TechRacho by BPS 株式会社</a></li>\n<li><a href=\"https://www.air-h.jp/articles/emopro/pdf%E3%81%8C%E8%AA%AD%E3%82%81%E3%82%8B%E3%82%88%E3%81%86%E3%81%AB%E3%81%AA%E3%82%8B%E3%81%8A%E8%A9%B1/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">PDF が読めるようになるお話 | 感情的プログラミング伝記 | タウン情報誌 AIR 函館 - 北海道函館市の食・呑・遊をご紹介！</a></li>\n</ul>\n<h2 id=\"おわりに\" style=\"position:relative;\"><a href=\"#%E3%81%8A%E3%82%8F%E3%82%8A%E3%81%AB\" aria-label=\"おわりに permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>おわりに</h2>\n<p>以上、画像ファイルフォーマットの基本について調べたり、少し中身を見てみました。</p>\n<p>画像ファイルをバイナリレベルで見るようなことはなかなかないと思いますが、少し覗いてみようとするだけでも結構勉強になりました。</p>\n<p>関連して、画像処理のアルゴリズムをまとめている良さそうなサイトも見かけたので、リンクを貼っておきます。</p>\n<ul>\n<li><a href=\"https://imagingsolution.blog.fc2.com/blog-entry-151.html\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">画像処理　画像処理ソリューション</a></li>\n</ul>","fields":{"slug":"/posts/image-file-format-basics","tagSlugs":["/tag/media/"],"autoRecommendPosts":["audio-video-streaming-data-basics","command-collection-for-binary-files","computer-graphics-first-step","media-and-xr-lonely-advent-calendar"]},"frontmatter":{"date":"2021-12-01T15:41:25.518Z","description":"画像ファイルフォーマットの基本について調べたことをまとめます。","tags":["media"],"title":"画像ファイルフォーマットの基本","socialImage":null,"recommendPosts":null}}},"pageContext":{"slug":"/posts/image-file-format-basics"}},"staticQueryHashes":["251939775","3942705351","401334301"]}