LoginSignup
2
1

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]});
2
1
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
2
1