我试图将360个PNG文件作为gif保存在R中的imagick(我正在与MacOS一起工作)
请让我知道我需要包含的任何其他系统/代码,因为我不熟悉将图像写入计算机。我正在创建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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Magick需要知道几件事(例如,图像大小,帧之间的延迟,要使用的图像,目标文件名),以便将PNG堆栈转换为GIF。请参阅 gif noreferrer“> gif anda and anda noriation and Animation meta-data ,
因此看起来您需要更改更改
为更多的东西,喜欢
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
So it looks like you need to change
to something more like