---
title: "Resize And Preserve Metadata"
canonical: https://www.graphicsmill.com/samples/Metadata/PreservingMetadata/ResizeAndPreserveMetadata_cs
product: "Graphics Mill"
source: "Metadata/PreservingMetadata/ResizeAndPreserveMetadata.cs"
---

# Resize And Preserve Metadata

Resize a JPEG and preserve/update metadata with Aurigma Graphics Mill.
Halves width (keeps aspect), updates EXIF Software, adds IPTC keyword,
sets Adobe copyright flag, adds XMP dc:contributor, and saves all metadata.

## Instruction

Resize an image while preserving EXIF, IPTC, Adobe resources, and XMP metadata.

## Usings

```csharp
using Aurigma.GraphicsMill.Codecs;
using Aurigma.GraphicsMill.Transforms;
```

## Code Snippet

```csharp
using (var jpegReader = new JpegReader("Chicago.jpg"))
using (var resize = new Resize(jpegReader.Width / 2, 0))
using (var jpegWriter = new JpegWriter("ResizeAndPreserveMetadata.jpg"))
{
    // Read EXIF
    var exif = jpegReader.Exif;

    // Check if loaded image contains EXIF metadata
    if (exif == null)
    {
        exif = new ExifDictionary();
    }

    exif[ExifDictionary.Software] = "Aurigma Graphics Mill";

    // Read IPTC
    var iptc = jpegReader.Iptc;

    // Check if loaded image contains IPTC metadata
    if (iptc == null)
    {
        iptc = new IptcDictionary();
    }

    iptc[IptcDictionary.Keyword] = "mountain";

    // Read Adobe resource blocks
    var adobeResources = jpegReader.AdobeResources;

    // Check if loaded image contains Adobe image resource blocks
    if (adobeResources == null)
    {
        adobeResources = new AdobeResourceDictionary();
    }

    // Create new adobe image resource block containing copyright metadata
    var arBlock = new AdobeResourceBlock("Copyright", new byte[] { 1 });

    // Set this block to the item with 0x040A ID (copyright flag)
    adobeResources[0x040A] = arBlock;

    var xmp = new XmpData();

    // Check if loaded image contains XMP metadata
    if (jpegReader.Xmp != null)
    {
        xmp.Load(jpegReader.Xmp);
    }

    // Create a node containing dc:contributor metadata
    var node = new XmpValueNode(XmpNodeType.SimpleProperty, "John Doe", XmpTagNames.DCContributor);
    xmp.AddNode(node);

    // Write metadata
    jpegWriter.Exif = exif;
    jpegWriter.Iptc = iptc;
    jpegWriter.AdobeResources = adobeResources;
    jpegWriter.Xmp = xmp.Save();

Pipeline.Run(jpegReader + resize + jpegWriter);
```

## Explanation

The code:

- Reads the input JPEG image and resizes it to half the width, keeping the height proportional.
- Retrieves and updates EXIF metadata to include the "Software" tag with the value "Aurigma Graphics Mill".
- Retrieves and updates IPTC metadata with a new keyword "mountain".
- Reads, modifies, and adds a new Adobe resource block for copyright metadata.
- Loads and updates XMP metadata, adding a contributor node with the value "John Doe".
- Writes the resized image along with the preserved and modified metadata to a new JPEG file.

## Tags

- [Adobe Resources](<https://www.graphicsmill.com/samples/tags/adobe-resources_md>): Working with Adobe image resource blocks
- [EXIF](<https://www.graphicsmill.com/samples/tags/exif_md>): Managing EXIF metadata
- [IPTC](<https://www.graphicsmill.com/samples/tags/iptc_md>): Managing IPTC metadata
- [Pipeline](<https://www.graphicsmill.com/samples/tags/pipeline_md>): Working with images via the Pipeline API
- [Read](<https://www.graphicsmill.com/samples/tags/read_md>): Reading images with codecs
- [Resize](<https://www.graphicsmill.com/samples/tags/resize_md>): Resizing images
- [Write](<https://www.graphicsmill.com/samples/tags/write_md>): Writing images with codecs
- [XMP](<https://www.graphicsmill.com/samples/tags/xmp_md>): Managing XMP metadata

## Input

- [Chicago.jpg](<https://www.graphicsmill.com/samples/Metadata/compiled/Debug/Chicago_jpg>) (preview)

## Output

- [ResizeAndPreserveMetadata.jpg](<https://www.graphicsmill.com/samples/Metadata/compiled/Debug/ResizeAndPreserveMetadata_jpg>) (preview)

## Used APIs

- [Aurigma.GraphicsMill.Codecs.AdobeResourceBlock](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_AdobeResourceBlock.htm.md>)
- [Aurigma.GraphicsMill.Codecs.AdobeResourceDictionary](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_AdobeResourceDictionary.htm.md>)
- [Aurigma.GraphicsMill.Codecs.ExifDictionary](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_ExifDictionary.htm.md>)
- [Aurigma.GraphicsMill.Codecs.ImageReader.AdobeResources](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_ImageReader_AdobeResources.htm.md>)
- [Aurigma.GraphicsMill.Codecs.ImageReader.Exif](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_ImageReader_Exif.htm.md>)
- [Aurigma.GraphicsMill.Codecs.ImageReader.Iptc](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_ImageReader_Iptc.htm.md>)
- [Aurigma.GraphicsMill.Codecs.ImageReader.Xmp](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_ImageReader_Xmp.htm.md>)
- [Aurigma.GraphicsMill.Codecs.IptcDictionary](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_IptcDictionary.htm.md>)
- [Aurigma.GraphicsMill.Codecs.JpegReader](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_JpegReader.htm.md>)
- [Aurigma.GraphicsMill.Codecs.JpegWriter](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_JpegWriter.htm.md>)
- [Aurigma.GraphicsMill.Codecs.JpegWriter.AdobeResources](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_JpegWriter_AdobeResources.htm.md>)
- [Aurigma.GraphicsMill.Codecs.JpegWriter.Exif](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_JpegWriter_Exif.htm.md>)
- [Aurigma.GraphicsMill.Codecs.JpegWriter.Iptc](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_JpegWriter_Iptc.htm.md>)
- [Aurigma.GraphicsMill.Codecs.JpegWriter.Xmp](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_JpegWriter_Xmp.htm.md>)
- [Aurigma.GraphicsMill.Codecs.XmpData](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_XmpData.htm.md>)
- [Aurigma.GraphicsMill.Codecs.XmpData.AddNode(XmpNode)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Codecs_XmpData_AddNode_1_79cf5b78.htm.md>)
- [Aurigma.GraphicsMill.Codecs.XmpData.Load(String)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Codecs_XmpData_Load_1_bb3a7a4f.htm.md>)
- [Aurigma.GraphicsMill.Codecs.XmpData.Save](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Codecs_XmpData_Save.htm.md>)
- [Aurigma.GraphicsMill.Codecs.XmpNodeType](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_XmpNodeType.htm.md>)
- [Aurigma.GraphicsMill.Codecs.XmpTagNames](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_XmpTagNames.htm.md>)
- [Aurigma.GraphicsMill.Codecs.XmpTagNames.DCContributor](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_XmpTagNames_DCContributor.htm.md>)
- [Aurigma.GraphicsMill.Codecs.XmpValueNode](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_XmpValueNode.htm.md>)
- [Aurigma.GraphicsMill.Transforms.Resize](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_Resize.htm.md>)
