是否可以使用php获取对象$image的文件大小(而不是图像大小)?我想把这个添加到我的“内容长度:”标题中。
$image = imagecreatefromjpeg($reqFilename);发布于 2013-01-31 23:19:26
我认为这应该是可行的:
$img = imagecreatefromjpeg($reqFilename);
// capture output
ob_start();
// send image to the output buffer
imagejpeg($img);
// get the size of the o.b. and set your header
$size = ob_get_length();
header("Content-Length: " . $size);
// send it to the screen
ob_end_flush();发布于 2013-01-31 23:13:07
您可以使用文件大小()来完成以下工作:
// returns the size in bytes of the file
$size = filesize($reqFilename);当然,只有当调整大小的映像是存储在磁盘上的映像时,如果在调用imagecreatefromjpeg()后要调整映像的大小,那么就应该使用@One技巧Ponys解决方案,并执行如下操作:
// load original image
$image = imagecreatefromjpeg($filename);
// resize image
$new_image = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
// get size of resized image
ob_start();
// put output for image in buffer
imagejpeg($new_image);
// get size of output
$size = ob_get_length();
// set correct header
header("Content-Length: " . $size);
// flush the buffer, actually send the output to the browser
ob_end_flush();
// destroy resources
imagedestroy($new_image);
imagedestroy($image);https://stackoverflow.com/questions/14636857
复制相似问题