我正在尝试像这样向客户端发送图像:
public function saveAction()
{
if(!isset($_SESSION)) session_start();
if(isset($_SESSION['id'])) {
$em = $this->getDoctrine()->getEntityManager();
$image = $em->getRepository('AcmeHomeBundle:Image')->find($_SESSION['id']);
// open the file in a binary mode
$fpass = fopen($image->getPath(), 'rb');
header("Content-Type: image/".$image->getFormat());
header("Content-Length: ".$image->getSize());
header('Content-Disposition: attachment; filename="image.'.$image->getFormat().'"');
// dump the picture and stop the script
fpassthru($fpass);
exit;
}
}
但有时会裁剪发送的图像。但是,原始图像是正确的。有什么可能出错的建议吗?
这是一个例子:
原图:
发送图片: