<p>You are correct, a front-end would be needed. It is however possible to limit by upload size (how many bytes).</p>

CC BY-SA 3.0
2014-07-16T13:12:35.280Z
Thanks Jeff - although the byte size limit is not what I need. I need for each image to be a specific width and height at upload. Anything more or less would not work for the layout, and image transform after upload could compromise the quality of the image, depending on what is uploaded.
Angela
CC BY-SA 3.0
2014-07-16T16:33:21.367Z
Very true - jQuery may have a nice uploader i would look there first.
Jeff Clayton
CC BY-SA 3.0
2014-07-16T20:17:06.653Z
There are new file methods available in modern browsers that are supposed to be able to do that. It may be a solution for you.
Jeff Clayton
CC BY-SA 3.0
2014-07-17T20:41:21.187Z
Most welcome, hope it works out!
Jeff Clayton
CC BY-SA 3.0
2014-07-16T02:23:51.823Z
2014-07-16T02:23:51.823Z
Jeff Clayton
<p>Currently, no. The only file-based validation Assets fields have right now is the type. If you want to enforce a certain size, you can do that on the template end using <a href="http://buildwithcraft.com/docs/image-transforms" rel="nofollow">image transforms</a>. I would suggest adding some instruction text to your Assets field that provides a minimum suggested size, and note that smaller images will be scaled up and look gross.</p>

<p>That said, if you <em>really</em> want to enforce a minimum width/height, or other properties, you can do so by writing a plugin that provides its own field type, which extends <a href="http://buildwithcraft.com/classreference/fieldtypes/AssetsFieldType" rel="nofollow">AssetsFieldType</a> and overrides its <a href="http://buildwithcraft.com/classreference/fieldtypes/AssetsFieldType#validate-detail" rel="nofollow">validate()</a> method with your custom validation:</p>

<pre class="lang-php prettyprint-override"><code>public function validate($value)
{
    // Let AssetsFieldType do its validation first
    $errors = parent::validate($value);

    if (!is_array($errors))
    {
        $errors = array();
    }

    if (is_array($value) &amp;&amp; !empty($value))
    {
        foreach ($value as $fileId)
        {
            $file = craft()-&gt;assets-&gt;getFileById($fileId);

            if ($file)
            {
                if ($file-&gt;width &lt; 600 || $file-&gt;height &lt; 400)
                {
                    $errors[] = Craft::t(
                        '{filename} must be at least 600x400px.',
                        array('filename' =&gt; $file-&gt;filename)
                    );
                }
            }
        }
    }

    if ($errors)
    {
        return $errors;
    }
    else
    {
        return true;
    }
}
</code></pre>

CC BY-SA 3.0
2014-10-09T10:29:03.043Z
2014-10-09T10:29:03.043Z
Brandon Kelly
<p>I believe you'd need to do some front-end pre-processing of the image to get it to the correct size(s) you require before passing it off to Craft.</p>

CC BY-SA 3.0
2014-07-16T18:04:44.023Z
2014-07-16T18:04:44.023Z
Brad Bell
<p>I think the transform feature is great, although in my case I need to request that certain images be uploaded at specific dimensions to an assets field. (i.e. 500 x 300 pixels). These dimensions will also need to be required on the front-end Guest Entries form. Although I don't see this option in the control panel or in the docs. Is this something that can be done?</p>

<assets>
How do you require specific dimensions when uploading an image?
# How do you require specific dimensions when uploading an image?

(Asked by: username_0 on 2014-07-16)

I think the transform feature is great, although in my case I need to request that certain images be uploaded at specific dimensions to an assets field. (i.e. 500 x 300 pixels). These dimensions will also need to be required on the front-end Guest Entries form. Although I don't see this option in the control panel or in the docs. Is this something that can be done?

**Tags:** assets

---

## 3 answers

### Answer by username_1 on 2014-07-16. Score: 2 | Accepted answer

You are correct, a front-end would be needed. It is however possible to limit by upload size (how many bytes).

> **Comments:**
> **username_0**: Thanks Jeff - although the byte size limit is not what I need. I need for each image to be a specific width and height at upload. Anything more or less would not work for the layout, and image transform after upload could compromise the quality of the image, depending on what is uploaded.  
> **username_1**: Very true - jQuery may have a nice uploader i would look there first.  
> **username_1**: There are new file methods available in modern browsers that are supposed to be able to do that. It may be a solution for you.  
> **username_1**: Most welcome, hope it works out!  

---

### Answer by username_2 on 2014-10-09. Score: 4

Currently, no. The only file-based validation Assets fields have right now is the type. If you want to enforce a certain size, you can do that on the template end using image transforms. I would suggest adding some instruction text to your Assets field that provides a minimum suggested size, and note that smaller images will be scaled up and look gross.
That said, if you really want to enforce a minimum width/height, or other properties, you can do so by writing a plugin that provides its own field type, which extends AssetsFieldType and overrides its validate() method with your custom validation:
public function validate($value)
{
    // Let AssetsFieldType do its validation first
    $errors = parent::validate($value);

    if (!is_array($errors))
    {
        $errors = array();
    }

    if (is_array($value) && !empty($value))
    {
        foreach ($value as $fileId)
        {
            $file = craft()->assets->getFileById($fileId);

            if ($file)
            {
                if ($file->width < 600 || $file->height < 400)
                {
                    $errors[] = Craft::t(
                        '{filename} must be at least 600x400px.',
                        array('filename' => $file->filename)
                    );
                }
            }
        }
    }

    if ($errors)
    {
        return $errors;
    }
    else
    {
        return true;
    }
}


---

### Answer by username_3 on 2014-07-16. Score: 2

I believe you'd need to do some front-end pre-processing of the image to get it to the correct size(s) you require before passing it off to Craft.


---

