【问题标题】:Download image or webpage with image from PHP webpage从 PHP 网页下载图像或带有图像的网页
【发布时间】:2019-11-25 02:55:54
【问题描述】:

我目前正在尝试编写一个 bash 脚本,以允许用户为需要打印的条形码(类型 C128)输入文本,然后:

  • 下载带有条码图像或仅图像的网页,然后在本地打印
  • 打印远程 URL 页面,将他们输入的文本作为要打印的 URL 的读取变量

特别是这个网站:

https://www.barcodesinc.com/generator/image.php?code=TEST1&style=165&type=C128B&width=388&height=150&xres=2&font=5

用任何文本替换 TEST1。

我尝试过使用 wget、curl、html2ps、html2ps + ps2pdf,但我遇到了源自 URL 页面基础的问题:

https://www.barcodesinc.com/generator/image.php

通过 CLI 我得到这个:

"需要条码类型ex.C39"

目的是在本地打印图片或保存后再打印。

这是我迄今为止尝试过的:

#!/bin/bash
echo -ne "Enter the ID you want to print: "
read locid

#html2ps https://www.barcodesinc.com/generator/image.php?code=LOCATION$locid&style=165&type=C128B&width=388&height=150&xres=2&font=5 | lpr

#html2ps https://www.barcodesinc.com/generator/image.php?code=LOCATION$locid&style=165&type=C128B&width=388&height=150&xres=2&font=5 | ps2pdf - /home/byron/locations/LOCATION$locid.pdf

#html2ps https://www.barcodesinc.com/generator/image.php?code=LOCATION$locid&style=165&type=C128B&width=388&height=150&xres=2&font=5 -o /home/byron/locations/LOCATION$locid.html
#ps2pdf /home/byron/locations/LOCATION$locid.html /home/byron/locations/LOCATION$locid.pdf

lpr /home/byron/locations/LOCATION$locid.pdf

当使用任何 CLI 工具时,我似乎得到一个空文件或标准输出输出。此外,打印作业会立即取消并显示“(stdin)到打印机”。

我尝试了https://unix.stackexchange.com/questions/168569/printing-webpage-using-browser-via-cli,但没有成功。

【问题讨论】:

    标签: php bash image curl wget


    【解决方案1】:

    barcodesinc.com 似乎不再支持盗链:只有在其自己域中的页面才能使用、打开或创建条形码图像...

    我建议使用不同的条形码图像服务器。比如我刚刚找到a10.selenode.com

    wget"https://a10.selenode.com/code128/TEST1"

    【讨论】:

      【解决方案2】:

      您为什么要尝试使用LOCATION$locid 而不仅仅是$locid

      #!/bin/bash
      
      read -p "enter LocationID:" locid
      
      wget -O $locid.gif "https://www.barcodesinc.com/generator/image.php?code=$locid&style=165&type=C128B&width=388&height=150&xres=2&font=5"
      

      成功下载了名为test1的图片

      【讨论】:

      • 我在变量之前使用了 LOCATION 这个词,因为条形码扫描仪需要在变量之前使用这个词 :)
      • 感谢您提供解决方案,看来我只需要用双引号将我的 wget 括起来,然后提供一个文件名 :)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-23
      • 2011-11-24
      相关资源
      最近更新 更多