在 symfony 文件上传中获取图像尺寸

Getting Image dimensions in symfony file upload

我想知道是否有人可以告诉我如何使用 formbulder 获取在 symfony 2.8 中上传的 i 文件的图像尺寸

图像实体有一个 属性 $文件

/*
 * @Assert\Image(
 *     minWidth = 400,
 *     maxWidth = 1200,
 *     minHeight = 400,
 *     maxHeight = 1200
 * )
 */
public $file;

在控制器中我构建了这样的表单

$form = $this->createFormBuilder($image)
        ->add('file', FileType::class)
        ->add('title', TextType::class)

然后处理请求

$form->handleRequest($request);

    if ($form->isSubmitted()) {

        $file = $image->getFile();
        if (!in_array($file->getClientMimeType(), self::$allowedMimeTypes)) {
            throw new \InvalidArgumentException(sprintf('Files of type %s are not allowed.', $file->getClientMimeType()));
        }

  [...]

我有两个setter方法

$image->setSizeX($x);
$image->setSizeY($y);

但老天爷还是想不出如何从文件对象中获取 $x 和 $y。

 $info = getimagesize($file);
 list($x, $y) = $info;