【问题标题】:ImageMagick causing captcha to be black outImageMagick 导致验证码变黑
【发布时间】:2017-04-26 01:05:39
【问题描述】:

我在使用 ImageMagick 时遇到问题。我通过 Homebrew 下载了 ImageMagick,由于某种原因,验证码显示为黑色。

这就是我得到的:

这是我正在使用的 ImageMagick 版本:

Hamels-MacBook-Air:gitreports HD$ magick -version
Version: ImageMagick 7.0.5-4 Q16 x86_64 2017-03-25 http://www.imagemagick.org
Copyright: © 1999-2017 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules
Delegates (built-in): bzlib freetype jng jpeg ltdl lzma png tiff xml zlib

这也是我在控制台中收到的内容:

Started GET "/issue/hd719/Bloc-Jams" for ::1 at 2017-04-25 21:02:29 -0400
Processing by RepositoriesController#repository as HTML
  Parameters: {"username"=>"hd719", "repositoryname"=>"Bloc-Jams"}
  User Load (1.0ms)  SELECT  "users".* FROM "users" WHERE "users"."username" = ? LIMIT 1  [["username", "hd719"]]
  Repository Load (0.3ms)  SELECT  "repositories".* FROM "repositories" INNER JOIN "repositories_users" ON "repositories"."id" = "repositories_users"."repository_id" WHERE "repositories_
users"."user_id" = ? AND "repositories"."name" = ?  ORDER BY name ASC LIMIT 1  [["user_id", 1], ["name", "Bloc-Jams"]]
  CACHE (0.0ms)  SELECT  "users".* FROM "users" WHERE "users"."username" = ? LIMIT 1  [["username", "hd719"]]
  CACHE (0.1ms)  SELECT  "repositories".* FROM "repositories" INNER JOIN "repositories_users" ON "repositories"."id" = "repositories_users"."repository_id" WHERE "repositories_users"."us
er_id" = ? AND "repositories"."name" = ?  ORDER BY name ASC LIMIT 1  [["user_id", 1], ["name", "Bloc-Jams"]]
  SimpleCaptcha::SimpleCaptchaData Load (0.2ms)  SELECT  "simple_captcha_data".* FROM "simple_captcha_data" WHERE "simple_captcha_data"."key" = ?  ORDER BY "simple_captcha_data"."id" ASC
 LIMIT 1  [["key", "438f5570aeba7ef4658ee2505ced9112e7221fa6"]]
   (0.7ms)  begin transaction
  SQL (1.1ms)  UPDATE "simple_captcha_data" SET "value" = ?, "updated_at" = ? WHERE "simple_captcha_data"."id" = ?  [["value", "SJZSRC"], ["updated_at", "2017-04-26 01:02:29.640800"], ["
id", 1]]
   (1.1ms)  commit transaction
  Rendered simple_captcha/_simple_captcha.erb (0.8ms)
  Rendered repositories/repository.html.erb within layouts/application (42.4ms)
  User Load (0.4ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1  [["id", 1]]
Completed 200 OK in 319ms (Views: 258.7ms | ActiveRecord: 4.9ms)


Started GET "/simple_captcha?code=438f5570aeba7ef4658ee2505ced9112e7221fa6&time=1493168549" for ::1 at 2017-04-25 21:02:30 -0400
  SimpleCaptcha::SimpleCaptchaData Load (0.2ms)  SELECT  "simple_captcha_data".* FROM "simple_captcha_data" WHERE "simple_captcha_data"."key" = ?  ORDER BY "simple_captcha_data"."id" ASC
 LIMIT 1  [["key", "438f5570aeba7ef4658ee2505ced9112e7221fa6"]]
  CACHE (0.0ms)  SELECT  "simple_captcha_data".* FROM "simple_captcha_data" WHERE "simple_captcha_data"."key" = ?  ORDER BY "simple_captcha_data"."id" ASC LIMIT 1  [["key", "438f5570aeba
7ef4658ee2505ced9112e7221fa6"]]

我还可以提供要求的任何其他信息。

-谢谢!

【问题讨论】:

  • 您需要添加生成捕获的代码。我猜这些字母背后的透明度是行不通的。我不确定,但我认为 V7 对某些透明度的处理与 V6 不同,代码可能需要更改。或者将字母背景更改为白色。
  • 嘿@Bonzo 你说的You need to add the code that generates the capture 是什么意思@ 我该怎么做? -谢谢。
  • 您一定在某处使用过一些 imagemagick 代码,或者您使用的是在网络上找到的一些代码?根据您安装 Imagemagick 的方式,您可能需要使用 magick 而不是在代码中进行转换,正如我所说,您可能需要更改 V7 透明度的代码。由于字母背景不透明,捕获可能是黑色的。
  • 我认为这是由SimpleCaptcha 生成的。默认设置将生成以下命令:convert -fill darkblue -background white -size 100x28 -wave 2x92 -gravity Center -pointsize 22 -implode 0.2 label:12345 temp.jpg
  • @emcconville 的代码对我有用,但在 Windows PC 上使用 magick 失败。我尝试移动一些选项但没有成功。

标签: imagemagick


【解决方案1】:

正如我在我的 cmets 中所说,@emcconville 发布的代码在 Windows PC 上为我工作。

使用 magick 时它失败了,因为我怀疑 magick ( V7 ) 需要以不同的顺序操作,因为它比 V6 更严格。所以这在我的电脑上再次为我工作:

magick -size 100x28 -background white -gravity Center -fill darkblue -pointsize 22  label:12345 -wave 2x92  -implode 0.2 "E:\Pictures\temp.jpg"

我猜 SimpleCapture 不兼容 V7;你有V6版本可以试试吗? 我使用的是 V7 版本,但它还内置了旧版 V6,但可能无法在 mac 上运行?

【讨论】:

  • 嘿,我感觉我做的不对,所以我运行代码magick -size 100x28 -background white -gravity Center -fill darkblue -pointsize 22 label:12345 -wave 2x92 -implode 0.2 "E:\Pictures\temp.jpg",得到的图像是12345
  • 是失真的 12345 吗?
  • 恐怕这就是@emcconville 发布的所有代码。但我会说这表明 SimpleCapture 不支持 V7。为了确认,我建议删除您的 V7 版本的 Imagemagick 并尝试 V6 版本。如果您正在构建一个网站,您可以在那里尝试 SimpleCapture 代码,如果它可以在您的 Mac 上忽略它并改为在线测试。
  • 是的。 12345 只是 FPO(仅用于放置)。该库会生成随机字符。
  • 请参阅this answer 以使用自制软件安装 ImageMagick 6。
猜你喜欢
  • 1970-01-01
  • 2018-03-13
  • 2018-06-07
  • 1970-01-01
  • 1970-01-01
  • 2020-12-01
  • 2011-05-11
  • 2013-12-25
  • 1970-01-01
相关资源
最近更新 更多