我试图将360个PNG文件作为gif保存在R中的imagick(我正在与MacOS一起工作)

发布于 2025-01-24 08:27:07 字数 949 浏览 2 评论 0原文

请让我知道我需要包含的任何其他系统/代码,因为我不熟悉将图像写入计算机。我正在创建360个png文件,如下所示:

for(theta in 1:360){
    ic=as.character(theta)
    if(theta<10) ic=paste("00",ic,sep="")
    if(theta>=10 & theta<100) ic=paste("0",ic,sep="") # make filenames the same length
    fn=paste("c:iris360\\HW4_",ic,".png",sep="") #filename
    png(fn,width=1000,height=1000) # save as *.png
    p3(X1,X2, r=100,theta=theta,mainL=paste("theta =",theta))
    # legend("topleft",pch=16,cex=1.5,col=allcl)
    dev.off()
}
system("magick c:iris360\\HW4*.png c:iris.gif") 

其中P3只是一个函数,它将我的矩阵x1和x2绘制点及其段(让我知道我是否还需要包含它)。但是,我得到了这个错误: magick:必须指定图像大小iris360hw4*.png' @ error/raw.c/readrawimage/140。

我无法打开GIF文件,因为我的Mac说它已损坏或使用文件格式该预览无法识别。

更新1:我替换了FN的声明,

fn <- sprintf("c:iris360/HW4_%03i.png", theta)

并用Sprintf(“%03i,theta,theta)代替IC,但仍有相同的指定图像大小错误。

当我将系统命令运行到终端时,我仍然会遇到相同的错误,要求我指定图像大小。

please let me know any other system/code I need to include, as I am not as familiar with writing out images to my computer. I am creating 360 png files as follows:

for(theta in 1:360){
    ic=as.character(theta)
    if(theta<10) ic=paste("00",ic,sep="")
    if(theta>=10 & theta<100) ic=paste("0",ic,sep="") # make filenames the same length
    fn=paste("c:iris360\\HW4_",ic,".png",sep="") #filename
    png(fn,width=1000,height=1000) # save as *.png
    p3(X1,X2, r=100,theta=theta,mainL=paste("theta =",theta))
    # legend("topleft",pch=16,cex=1.5,col=allcl)
    dev.off()
}
system("magick c:iris360\\HW4*.png c:iris.gif") 

where p3 is just a function that takes my matrices X1 and X2 and plots the points and their segments(let me know if I need to include it as well). However, I get this error:
magick: must specify image size iris360HW4*.png' @ error/raw.c/ReadRAWImage/140.

I am unable to open the gif file, as my mac says it is damaged or uses a file format that preview does not recognize.

Update 1: I replaced fn's declaration with

fn <- sprintf("c:iris360/HW4_%03i.png", theta)

as well as replacing ic with sprintf("%03i", theta) everywhere it appeared, but still got the same specify image size error.

When I run the system command into my terminal, I still get the same error asking me to specify the image size.

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

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

发布评论

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

评论(1

世界如花海般美丽 2025-01-31 08:27:07

Magick需要知道几件事(例如,图像大小,帧之间的延迟,要使用的图像,目标文件名),以便将PNG堆栈转换为GIF。请参阅 gif noreferrer“> gif anda and anda noriation and Animation meta-data

magick -delay 100  -size 100x100 xc:SkyBlue \
      -page +5+10  balloon.gif   -page +35+30 medical.gif  \
      -page +62+50 present.gif   -page +10+55 shading.gif  \
      -loop 0  animation.gif

因此看起来您需要更改更改

system("magick c:iris360\\HW4*.png c:iris.gif")

为更多的东西,喜欢

system("magick -delay 10 -size 100x100 —loop 0 c:iris360\\HW4*.png c:iris.gif")

Magick needs to know several things (e.g., image size, delay between frames, images to use, destination file name) in order to convert a stack of png into a gif. See GIF Animations and Animation Meta-data

magick -delay 100  -size 100x100 xc:SkyBlue \
      -page +5+10  balloon.gif   -page +35+30 medical.gif  \
      -page +62+50 present.gif   -page +10+55 shading.gif  \
      -loop 0  animation.gif

So it looks like you need to change

system("magick c:iris360\\HW4*.png c:iris.gif")

to something more like

system("magick -delay 10 -size 100x100 —loop 0 c:iris360\\HW4*.png c:iris.gif")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文