5.1.4. image

An image field is really just a special variant of the file field type, allowing for nicer presentation in the administrative pages, and a bit of scaling.

The simplest example is this:

<field id="illustration" type="image" multiLingual="0">
  <title lang="en">Image</title>
  <title lang="da">Billede</title>
</field>

Now the image will be uploaded but not scaled in any way. However, often you want to limit the file size of the images people put into the system - read on to learn the syntax.

5.1.4.1. Scaling

One of the things that sets the image type aside from the generic file type is that you can scale images immediately upon upload. A simple scaling could be defined like this:

<field id="illustration" type="image" multiLingual="0">
  <title lang="en">Image</title>
  <title lang="da">Billede</title>
  <scaling xy="800"/>
</field>

Now the image will be scaled down to a maximum of 800 pixels on both axis.

If you want the scale down based on the x-axis you can do this:

<field id="illustration" type="image" multiLingual="0">
  <title lang="en">Image</title>
  <title lang="da">Billede</title>
  <scaling x="800"/>
</field>

And of course the same goes for the y-axis:

<field id="illustration" type="image" multiLingual="0">
  <title lang="en">Image</title>
  <title lang="da">Billede</title>
  <scaling y="800"/>
</field>

You can also combine the two and make sure that an image is never bigger than 400 pixels on the x-axis and 200 on the y-axis:

<field id="illustration" type="image" multiLingual="0">
  <title lang="en">Image</title>
  <title lang="da">Billede</title>
  <scaling x="400" y="200"/>
</field>

Note

If you don't need an image in a number of sizes but always the same, fixed size, scaling this way at upload time will give you superior performance.

No matter which combination of scaling attributes you use the following is always obeyed:

  • Proportions are kept - the system will not skew you image in any way to meet your scaling requirements.

  • An image is never scaled up - if the uploaded image is smaller than your scaling attributes, it will be left as-is.

5.1.4.2. Limiting uploads to specific mime types

You can use the mimetypes rule to limit the types of files your field allows.