Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Image dimensions in symfony file upload

I was wondering if someone could tell me how to get the image dimensions of i file uploaded in symfony 2.8 with formbulder

The image entity had a property $file

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

In the controller i build the form like this

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

And then process the request

$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()));
        }

  [...]

I have two setter mehods

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

But cannot for the love of god figure out how to get $x and $y from the file object.

like image 562
Sangit Avatar asked Oct 19 '25 03:10

Sangit


1 Answers

 $info = getimagesize($file);
 list($x, $y) = $info;
like image 142
delpi Avatar answered Oct 21 '25 16:10

delpi