如何将 JPEG 图像旋转 45°并将其保存回 Haskell 中的磁盘?

发布于 2024-09-12 14:29:47 字数 34 浏览 8 评论 0原文

如何将 JPEG 图像旋转 45° 并将其保存回磁盘?

How do I rotate a JPEG image by 45° and save it back to disk?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

奢望 2024-09-19 14:29:47

据我所知,Haskell 还没有好的图像处理库。

更好的方法

您可以使用hsmagick(绑定到libmagick)来操作图像。

请参阅TomMD 的回答作为示例。

简单的方法

但是如果你想从 Haskell 做到这一点,这可以做到这一点(假设 ImageMagick 可用):

import System.Cmd (system)
import System.Environment (getArgs)

main = do
  (original:rotated:_) <- getArgs
  system $ "convert -rotate \"-45\" \"" ++ original ++ "\" \"" ++ rotated ++ "\""

用法:

runghc rotate.hs original.jpg rotated45.jpg

困难的方法

或者你可以选择困难的方法,并实现 旋转算法。要在 Haskell 中读取和写入几乎所有图像格式,您可以使用 Codec.Image.DevIL< /a> 库。如果您这样做,将这段代码放在 Hackage 上真是太好了。

As far as I know, there is no good image manipulation library for Haskell yet.

Better way

You can use hsmagick (bindings to libmagick) to manipulate images.

See TomMD's answer for an example.

Easy way

But if you want to do it from Haskell, this can do the trick (assuming that ImageMagick is available):

import System.Cmd (system)
import System.Environment (getArgs)

main = do
  (original:rotated:_) <- getArgs
  system $ "convert -rotate \"-45\" \"" ++ original ++ "\" \"" ++ rotated ++ "\""

Usage:

runghc rotate.hs original.jpg rotated45.jpg

Hard way

Or you can choose the hard way, and implement rotation algorithm yourself. To read and write almost all image formats in Haskell, you can use Codec.Image.DevIL library. If you do it, it would be kind of you to put this code on Hackage.

情话已封尘 2024-09-19 14:29:47

GD 库可以让你做到这一点,但是 Haskell 绑定 ( http://hackage.haskell.org/package /gd )目前不包含适当的函数。人们还可以向维护者提出功能请求,或者简单地修补它并将其发送到上游。 Graphics.GD.Internal 模块(未导出)实际上已经有一个注释掉的绑定到适当的函数( http://hackage.haskell.org/packages/archive/gd/3000.5.0/doc/html/src/Graphics-GD- Internal.html ),所以我想,完成这项工作应该非常简单(而且我确信,这项工作将受到赞赏)。

The GD library lets you do this, but the Haskell bindings ( http://hackage.haskell.org/package/gd ) don't include the appropriate function at the moment. One also could either make a feature request to the maintainer, or simply patch it and send it upstream. The Graphics.GD.Internal module (not exported) in fact already has a commented out binding to the appropriate function ( http://hackage.haskell.org/packages/archive/gd/3000.5.0/doc/html/src/Graphics-GD-Internal.html ), so it should be very simple, I imagine, to finish the job (and I'm sure, the work will be appreciated).

南风几经秋 2024-09-19 14:29:47

在 Hackage 上四处看看。我知道 Tim 开始致力于 libmagick 的绑定,但这并不足以阻止我放弃当我需要图像处理时,可以为 GIMP 生成 script-fu,但如果你只是做旋转等简单的事情,这对你来说就足够了:

liftM (rotateImage 45) (readImage file) >>= writeImage file2

我看到 Cale 也有一个 ImLib 看起来功能更完整:

loadImageImmediately file >>= contextSetImage >>
createRotatedImage 45 >>= contextSetImage >> saveImage file2

正如我所说,环顾四周并让我们知道!

Look around on Hackage. I know Tim started working on bindings to libmagick, which wasn't enough to stop me from dropping down to generating script-fu for GIMP when I needed image manipulation, but it's enough for you if you're just doing simple things like rotation:

liftM (rotateImage 45) (readImage file) >>= writeImage file2

I see Cale also has an ImLib that appears more feature complete:

loadImageImmediately file >>= contextSetImage >>
createRotatedImage 45 >>= contextSetImage >> saveImage file2

As I said, look around and let us know!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文