1

我无法使用 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)。我能做些什么?

4

1 回答 1

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

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

于 2011-08-30T23:16:18.737 回答