使用识别时,imagemagick 在动画 gif 上返回大量尺寸值

发布于 2024-11-03 15:31:35 字数 1776 浏览 5 评论 0原文

我在使用 imagemagick 的识别命令获取图像的尺寸时遇到问题:

identify -format "%w^%h" 

对于动画 gif,它返回大型数组,例如:

Array ( [0] => 500 [1] => 322500 [2] => 322307 [3] => 178151 [4] => 322500 [5] => 178500 [6] => 322500 [7] => 322500 [8] => 322500 [9] => 302500 [10] => 322306 [11] => 303500 [12] => 303500 [13] => 322500 [14] => 317381 [15] => 322500 [16] => 322500 [17] => 178500 [18] => 178500 [19] => 322151 [20] => 322500 [21] => 178500 [22] => 322500 [23] => 322500 [24] => 322500 [25] => 302500 [26] => 322306 [27] => 303500 [28] => 303500 [29] => 322500 [30] => 317381 [31] => 322500 [32] => 322500 [33] => 178500 [34] => 178500 [35] => 322151 [36] => 322500 [37] => 178500 [38] => 322500 [39] => 322500 [40] => 322500 [41] => 302500 [42] => 322306 [43] => 303500 [44] => 303500 [45] => 322500 [46] => 317381 [47] => 322500 [48] => 322500 [49] => 178500 [50] => 178500 [51] => 322151 [52] => 322500 [53] => 178500 [54] => 322500 [55] => 322500 [56] => 322500 [57] => 302500 [58] => 322306 [59] => 303500 [60] => 303500 [61] => 322500 [62] => 317381 [63] => 322500 [64] => 322500 [65] => 178500 [66] => 178500 [67] => 322151 [68] => 322500 [69] => 178500 [70] => 322500 [71] => 322500 [72] => 322500 [73] => 302500 [74] => 322306 [75] => 303500 [76] => 303500 [77] => 322500 [78] => 317381 [79] => 322500 [80] => 322500 [81] => 17827 [82] => 2127 [83] => 2127 [84] => 2127 [85] => 2127 [86] => 2127 [87] => 21 ) 

我假设它正在获取每个帧的尺寸。这使得很难获得正确的尺寸,在本例中为 (500x322)。我能做些什么?

I am having trouble getting the dimensions of an image using imagemagick's identify command:

identify -format "%w^%h" 

For animated gifs it returns large arrays such as:

Array ( [0] => 500 [1] => 322500 [2] => 322307 [3] => 178151 [4] => 322500 [5] => 178500 [6] => 322500 [7] => 322500 [8] => 322500 [9] => 302500 [10] => 322306 [11] => 303500 [12] => 303500 [13] => 322500 [14] => 317381 [15] => 322500 [16] => 322500 [17] => 178500 [18] => 178500 [19] => 322151 [20] => 322500 [21] => 178500 [22] => 322500 [23] => 322500 [24] => 322500 [25] => 302500 [26] => 322306 [27] => 303500 [28] => 303500 [29] => 322500 [30] => 317381 [31] => 322500 [32] => 322500 [33] => 178500 [34] => 178500 [35] => 322151 [36] => 322500 [37] => 178500 [38] => 322500 [39] => 322500 [40] => 322500 [41] => 302500 [42] => 322306 [43] => 303500 [44] => 303500 [45] => 322500 [46] => 317381 [47] => 322500 [48] => 322500 [49] => 178500 [50] => 178500 [51] => 322151 [52] => 322500 [53] => 178500 [54] => 322500 [55] => 322500 [56] => 322500 [57] => 302500 [58] => 322306 [59] => 303500 [60] => 303500 [61] => 322500 [62] => 317381 [63] => 322500 [64] => 322500 [65] => 178500 [66] => 178500 [67] => 322151 [68] => 322500 [69] => 178500 [70] => 322500 [71] => 322500 [72] => 322500 [73] => 302500 [74] => 322306 [75] => 303500 [76] => 303500 [77] => 322500 [78] => 317381 [79] => 322500 [80] => 322500 [81] => 17827 [82] => 2127 [83] => 2127 [84] => 2127 [85] => 2127 [86] => 2127 [87] => 21 ) 

I am assuming it is getting the dimensions of each frame. This is making it difficult to get the correct dimensions which is (500x322) in this case. What can I do?

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

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

发布评论

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

评论(1

寻梦旅人 2024-11-10 15:31:35
exec('identify -format "%w%h\n" image.gif', $output)
foreach($output as $line) {
    $i = explode(" ", $line);
    $w = $i[0];
    $h = $i[1];
}

这应该可行 - ImageMagick 将以可爆炸的格式将信息打印在一行上,然后转到下一行。您可能需要跳过 $output 的最后一行,因为它可能设置为空白。

exec('identify -format "%w%h\n" image.gif', $output)
foreach($output as $line) {
    $i = explode(" ", $line);
    $w = $i[0];
    $h = $i[1];
}

That should work - ImageMagick will print the info on one line in an explode-able format and then go to the next line. You may need to skip the last line of $output as it may be set to blank.

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