サイト制作に関するメモ書き

HOME > HTML・CSS > svgをimgタグで埋め込んだ際にchromeで表示されない

svgをimgタグで埋め込んだ際にchromeで表示されない

Photoshopでsvgを書き出してimgタグで埋め込んだ時に、chromeでだけうまく表示されない不具合に遭遇したので対応方法をメモ。
chromeのバージョンは72.0.3626.121、Photoshopのバージョンは20.0.0を使用しています。

発生した条件

Photoshop上でスマートオブジェクトをsvg形式で書き出します。

以下のような内容で書き出されました。

star.svg

<svg id="star.svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="190" viewBox="0 0 200 190">
  <image id="star" width="200" height="190" xlink:href="data:img/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAAC+CAYAAABwI0BCAAAOdUlEQVR4nO2deaxdRR3Hv9SWshZkkeWUIrUtmyxTRVEwYRU1gkYWRRwBUQGjFLRCJabVCrEsQRGiJoKKJwIJRgz+IYKAhFUwHWgFoWAxwLBJCWsXtpqhv9fe9+bd++4968w5309yk5eZc9+ZM+d+72/u/JYDEg7W6CPdi7ckHNZr+wSEgjV6fQAPyHB2T1T6etvnJATGtX0CAuJkANPkdXLbJyMUaEECwBq9OYBHAWwpo1nmhJKo9MVWT0wA0IKEwZwOcUD+ntPmCQkFWpCasUZPAfAwgA1GjGQlgJ0TlT7eukkJCFqQ+jl3FHFA2s71Wkml0ILUiDV6JoB/9rgPqwF8MFHpQq+HVAItSL1c0EMckL4LvFZSGRRITVijPw3goD7OfpAcS2qg17cXKQlr9HgA9zmHYJ9ncA7EvROVvun1kFKhBamHEwcQB+TYE71WUjq0IBVjjd4EwCMAth3wzM8AmJ6o9FWvh5QGLUj1zM4gDsh7ZnutpFRoQSrEGr2dWI+NM571NbEiT3s9pBRoQaplfg5xQN4732slpUELUhHW6PfLztW7cp7xLdnR+pfXQwqHFqQ6FhQgDsj/OM9rJaVAC1IB1uiDAfyt4DMdkqj0Jq+VFAoFUjLW6HESb6UKPpOROK23vR5SGFxilc9xJYgD8j+P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ます。

<img src="star.svg">

この場合chromeでうまく表示できませんでした。
うまく表示できなかった場合のデモページ

原因としては、svgのimage要素でxlink:hrefの値がdata:img/png; 〜 となっていると発生するようです。
data:image/png; とすると表示されるようになりました。

<svg id="star.svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="190" viewBox="0 0 200 190">
  <image id="star" width="200" height="190" xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAAC+CAYAAABwI0BCAAAOdUlEQVR4nO2deaxdRR3Hv9SWshZkkeWUIrUtmyxTRVEwYRU1gkYWRRwBUQGjFLRCJabVCrEsQRGiJoKKJwIJRgz+IYKAhFUwHWgFoWAxwLBJCWsXtpqhv9fe9+bd++4968w5309yk5eZc9+ZM+d+72/u/JYDEg7W6CPdi7ckHNZr+wSEgjV6fQAPyHB2T1T6etvnJATGtX0CAuJkANPkdXLbJyMUaEECwBq9OYBHAWwpo1nmhJKo9MVWT0wA0IKEwZwOcUD+ntPmCQkFWpCasUZPAfAwgA1GjGQlgJ0TlT7eukkJCFqQ+jl3FHFA2s71Wkml0ILUiDV6JoB/9rgPqwF8MFHpQq+HVAItSL1c0EMckL4LvFZSGRRITVijPw3goD7OfpAcS2qg17cXKQlr9HgA9zmHYJ9ncA7EvROVvun1kFKhBamHEwcQB+TYE71WUjq0IBVjjd4EwCMAth3wzM8AmJ6o9FWvh5QGLUj1zM4gDsh7ZnutpFRoQSrEGr2dWI+NM571NbEiT3s9pBRoQaplfg5xQN4732slpUELUhHW6PfLztW7cp7xLdnR+pfXQwqHFqQ6FhQgDsj/OM9rJaVAC1IB1uiDAfyt4DMdkqj0Jq+VFAoFUjLW6HESb6UKPpOROK23vR5SGFxilc9xJYgD8j+P81pJodCClIg1ekPJ9dihpLM8ITkjK7weUgi0IOUyq0RxQP73LK+VFAYtSElYo7eSPPPNSj7VS5K//rzXQ3JDC1Ie8yoQB+Qc87xWUgi0ICVgjZ4uIeoTKjrlG1JL6x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xID3kS/wzgx4lK7/J6aiJRqVu6/MW9rNEfAfA9AIeHMr4RUCAFENokOutwlfgwHvR6A0KEe4Q1ejfxpRwb2D2nQAoglElcDuByABcmKn3c6w0YEfKXrdHfBzAbwEkANgpgxBRIAdQ9iS8AuBTAJYlKn/d6I0KEfZo1ej6AbwH4JoAtaryC4AUSwzbvUwC28zrKx/leLgLwq0Slr9Zw/tKxRm8C4GsAvg2gDp9E8L6QoAVijZ4oPpAqeciFggD4fSy1m/IivqbjJJRllwpPHbwvJPRt3h29lvK4B8DnAOyeqPQ3bREH1iy9XnfX7K5d5uAe76ByCN4XEvpvkCrWqDfIjtQtXk/LSFTqngB1rXtZow+Una+PlzwLzvvfV+BmHbRVIO6DcA2A8xKVGq+XQL4wbrFGKwBnATi6pBVH0OExbRPIKhcfJVu1wX5rhYR8gXyhY4vYxX1NLHCIQe9ktUUgLwNw8UoXZw03bzvyhXKKNfqHEkF8KoBJBUwLBZKDvJP3LICfulyMosPN24p8wcyxRi+QnJTTAWyTYzqCFkjo27xZfSBLJdz8iioiatuMhNsfL+H2UzNMxdOJSrf3WgMhWIFk9IHc73akXL53HRG1bcYaPV7y5t3O114DToXzhazyWgMgZD/IID6QWwF8EoBKVHo1xVE9Em5/tbsHci9uHWAQVfq7BiLk3yBjrU2dF/Y68WHc7fWSWpBw++vdyxq9r1iUI8ZYrbh7vcRrDYAYBfIGgCulMkjQ4eZtR764Pivh9mdKxuOEUaal272unZgE8hqAy1wAYWzh5m1HvshOsEbPlcDIrwLYuGNaKJAMDE3aMgk3vzT2cPO2I19sp1ujz5FQe/fakgLJxjip/3RZU8PN24p80f3AGn2hWBP3WyU8APwfoHio8DGKUNkAAAAASUVORK5CYII="/>
</svg>

対応後のデモページ
 

【参考サイト】

 

コメントは受け付けていません。

▲PAGE TOP