AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 718453
Accepted
Nicolas Raoul
Nicolas Raoul
Asked: 2016-01-08 23:03:11 +0800 CST2016-01-08 23:03:11 +0800 CST 2016-01-08 23:03:11 +0800 CST

如何轻松缩放从高 DPI 屏幕截取的屏幕截图?

  • 772

由于我切换到高 DPI 显示,我发布的屏幕截图非常大,示例如下。

有没有办法快速让它们看起来正常?
最好是比启动 GIMP 更快的东西。

特别是,在 gnome-screenshot 中是否有隐藏选项?

在此处输入图像描述

  • 可能没有完美的工具,因为使 Ubuntu 适应高 DPI 的方式并不统一(字体、窗口装饰、程序,可能有不同的比例),但是一个好的工具会读取这些设置并找出最好的比例使用.
  • 最好我想保留只选择屏幕的一部分(如在 SHIFT+PRTSCR 中)并选择文件名的能力。
  • 万一这很重要,我总是将我的屏幕截图保存在$HOME/Pictures.
command-line
  • 2 2 个回答
  • 2491 Views

2 个回答

  • Voted
  1. Best Answer
    Jacob Vlijm
    2016-01-09T04:15:20+08:002016-01-09T04:15:20+08:00

    1. 像往常一样截图,然后用快捷键自动缩放你最近截的截图。

    放置在快捷键下,下面的脚本将:

    1. 在您的屏幕截图目录中找到最后~/Picures添加的屏幕截图(正如您在评论中提到的那样)
    2. 将图像缩放为任意百分比
    3. 将图像重命名并另存为renamed_filename.png,filename.png原始文件名在哪里。

    如何使用

    1. 该脚本需要python3-pil安装库,您的系统可能并非如此:

      sudo apt-get install python3-pil
      
    2. 将下面的脚本复制到一个空文件中,另存为resize_screenshot.py

    3. 通过截屏测试运行脚本,然后通过以下命令运行脚本:

      python3 /path/to/resize_screenshot.py 80
      

      其中80是所需的输出大小百分比。该脚本现在创建了最后一个屏幕截图的调整大小的副本。

    4. 如果一切正常,请将其添加到快捷键:系统设置 > 键盘 > 快捷方式 > 自定义快捷方式。添加命令:

      python3 /path/to/resize_screenshot.py 80
      

    剧本

    #!/usr/bin/env python3
    import os
    import sys
    from PIL import Image
    
    percent = float(sys.argv[1])/100
    
    
    pic_list = []
    # list all .png files in ~/Pictures
    pic_dir = os.environ["HOME"]+"/Pictures"
    files = [pic_dir+"/"+f for f in os.listdir(pic_dir) if \
             all([f.endswith(".png"), not f.startswith("resized")])]
    # create a sorted list + the creation date of relevant files
    pics = [[f, int(os.stat(f).st_ctime)] for f in files]
    pics.sort(key=lambda x: x[1])
    # choose the latest one
    resize = pics[-1][0]
    # open the image, look up its current size
    im = Image.open(resize)
    size = im.size
    # define the new size; current size * the percentage
    newsize = [int(n * percent) for n in size]
    # resize the image, save it as renamed file (keeping original)
    im.thumbnail(newsize, Image.ANTIALIAS)
    newfile = pic_dir+"/resized_"+resize.split("/")[-1]
    im.save(newfile, "png")
    

    一个例子

    您的图像示例,通过以下方式调整大小:

    python3 <script> 80
    

    在此处输入图像描述


    2.全自动选项

    虽然上面的脚本在快捷键上完成了它的工作,但您可以使用后台脚本使其完全自动运行。您的脚本所做的只是检查 中的新文件~/Picures,并像在第一个脚本中一样执行重新缩放操作。

    剧本

    #!/usr/bin/env python3
    import os
    import sys
    from PIL import Image
    import time
    
    percent = float(sys.argv[1])/100
    pic_dir = os.environ["HOME"]+"/Pictures"
    
    def pics_list(dr):
        return [pic_dir+"/"+f for f in os.listdir(pic_dir) if \
                all([f.endswith(".png"), not f.startswith("resized")])]
    
    def scale(f):
        #open the image, look up its current size
        im = Image.open(f)
        size = im.size
        # define the new size; current size * the percentage
        newsize = [int(n * percent) for n in size]
        # resize the image, save it as renamed file (keeping original)
        im.thumbnail(newsize, Image.ANTIALIAS)
        newfile = pic_dir+"/resized_"+f.split("/")[-1]
        im.save(newfile, "png")
    
    p_list1 = pics_list(pic_dir)
    while True:
        time.sleep(2)
        p_list2 = pics_list(pic_dir)
        for item in p_list2:
            if not item in p_list1:
                scale(item)
        p_list1 = p_list2
    

    如何使用

    设置与上面的脚本完全相同(“如何使用”),但不是[4.]将其添加到 Startup Applications:Dash > Startup Applications > Add。添加命令:

    python3 /path/to/resize_screenshot.py 80
    

    3. 带有刻度对话框的全自动选项

    几乎相同的脚本,但现在带有比例对话,在您将图像保存到之后~/Pictures立即:

    在此处输入图像描述

    此屏幕截图自动调整为 80% :)

    剧本

    #!/usr/bin/env python3
    import os
    import sys
    from PIL import Image
    import time
    import subprocess
    
    # --- change if you like the default scale percentage, as proposed by the slider:
    default_percent = 80
    # --- change if you like the screenshot directory
    pic_dir = os.environ["HOME"]+"/Pictures"
    # ---
    
    def pics_list(dr):
        return [pic_dir+"/"+f for f in os.listdir(pic_dir) if \
                all([f.endswith(".png"), not f.startswith("resized")])]
    
    def scale(f, size):
        #open the image, look up its current size
        im = Image.open(f)
        currsize = im.size
        # define the new size; current size * the percentage
        newsize = [int(n * size) for n in currsize]
        # resize the image, save it as renamed file (keeping original)
        im.thumbnail(newsize, Image.ANTIALIAS)
        newfile = pic_dir+"/resized_"+f.split("/")[-1]
        im.save(newfile, "png")
    
    p_list1 = pics_list(pic_dir)
    while True:
        time.sleep(2)
        p_list2 = pics_list(pic_dir)
        for item in p_list2:
            if not item in p_list1:
                try:
                    size = subprocess.check_output([
                        "zenity", "--scale",
                        "--value="+str(default_percent),
                        ]).decode("utf-8")
                    scale(item, float(size)/100)
                except subprocess.CalledProcessError:
                    pass
        p_list1 = p_list2
    

    使用

    设置与上面完全相同,除了命令之外,现在没有比例百分比:

    python3 /path/to/resize_screenshot.py
    

    笔记

    与往常一样,后台脚本实际上不使用任何资源,除非您的~/Pictures目录非常大:)。

    • 4
  2. Takkat
    2016-01-09T00:34:15+08:002016-01-09T00:34:15+08:00

    使用gnome-screenshot我们无法缩放输出。

    要自动执行此操作,我们可以将另一个屏幕截图终端应用程序分配给快捷方式。

    50% 大小的屏幕截图示例:

    1. 图像魔术 到原始百分比安装 imagemagick import -resize
    • 截取整个桌面的截图:

           import -window root -resize 50% [-delay <value>] shot.png
      
    • 截取窗口的屏幕截图(可通过鼠标选择):

           import -window $(xdotool selectwindow) resize 50% shot.png
      
    • 截取窗口并显示结果:

           import -window $(xdotool selectwindow) -resize 50% shot.png && display shot.png
      
    • 将屏幕截图加载到任何其他外部查看器(例如eog)

           import -window $(xdotool selectwindow) -resize 50% shot.png && eog shot.png
      
    1. scrot (manpage)输出到 Image Magic以选择屏幕区域安装 scrot convert

       scrot <options> -e "convert \$f -resize 50% shot.png && rm \$f"
       <options>
       -s select window or rectangle with mouse
       -u use currently focused windows
      

    下面的示例将显示,然后使用 scrot 的默认文件名(日期/小时/分钟/秒/大小)在我们的图片目录中保存所选区域或窗口的一半大小 (50%) 的屏幕截图:

        scrot -s -e "convert \$f -resize 50% ~/Pictures/\$f && display \$f && rm \$f"
    
    • 2

相关问题

  • 如何从命令行仅安装安全更新?关于如何管理更新的一些提示

  • 如何从命令行刻录双层 dvd iso

  • 如何从命令行判断机器是否需要重新启动?

  • 文件权限如何工作?文件权限用户和组

  • 如何在 Vim 中启用全彩支持?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve