3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

webpをjpgかpngに変換するブックマークレット

Last updated at Posted at 2020-06-04

あったら良いなと思って勉強がてら作ってみました。Chromeで動きました。
新しいタブで画像を開いた時に使えます。末尾を弄ると保存する時の名前とか形式とかを変えられるようにしてみました。

javascript:(({quality, fileName, format}) => {

  let img = document.getElementsByTagName('img')[0];
  let make = (t, p) => Object.assign(document.createElement(t), p);
  let cv = make('canvas', { width: img.naturalWidth, height: img.naturalHeight });
  cv.getContext('2d').drawImage(img, 0, 0);
  cv.toBlob(b => make('a', { href: URL.createObjectURL(b), download: fileName }).click(), 'image/' + format, quality - 0);

})({quality:0.92, fileName:'tempoName', format:{0:'png', 1:'jpeg', 2:'webp'}[1]});
3
2
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
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?