1
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?

クリップボードに保存されている画像の解像度を半分にするツールを作ってみた

Last updated at Posted at 2025-09-09

なぜこの記事を書こうと思ったのか

普段、CodiMDNotionをよく使うのですが、クリップボードにコピーした画像を小さくして貼り付けたい場面がよくありました。
Photoshopやペイントを起動して小さくするのも面倒だったので、ツールを実行するとクリップボードに保存されている画像の解像度を半分にして上書きするツールを作ってみました。

出来上がったもの

image.png
↑クリップボードに保存されている画像
↓ツールを実行するとクリップボードの画像解像度が半分になる
image2.png

コード

Cargo.toml
[package]
name = "clipboard_half_image"
version = "0.1.0"
edition = "2024"

[dependencies]
arboard = "3.6.1"
image = "0.25.6"
main.rs
fn main() {
    let clipboard = arboard::Clipboard::new();
    let Ok(mut ctx) = clipboard else {return};
    let Ok(img) = ctx.get_image() else {return};
    let Some(cb_img) = image::RgbaImage::from_vec(img.width as u32, img.height as u32, img.bytes.to_vec()) else {return};
    let n_width = (img.width as f32 * 0.5) as u32;
    let n_height = (img.height as f32 * 0.5) as u32;
    let di = image::DynamicImage::from(cb_img);
    let resize_di =  di.resize(n_width, n_height, image::imageops::FilterType::Lanczos3);
    let n_img = arboard::ImageData {
        width: resize_di.width() as usize,
        height: resize_di.height() as usize,
        bytes: resize_di.as_bytes().as_ref().into(),
    };
    let _res = ctx.set_image(n_img);
}

参考にさせていただいたサイト

https://github.com/1Password/arboard/blob/master/examples/get_image.rs
https://github.com/1Password/arboard/blob/master/examples/set_image.rs

1
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
1
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?