Sub topic 1
How Photoshop documents work: canvas, pixels, and the file lifecycle
Every later chapter in this tutorial depends on one model. A Photoshop document is a working copy held in memory. A file on disk is a snapshot of that working copy in one particular format. This chapter explains the model, so that opening, creating, and saving make sense before you meet the individual formats.
Prerequisites
This chapter assumes you already have the following:
- You can find your way around the Photoshop workspace: the menu bar, the Tools panel, and panels such as Layers and History.
- You know that a raster image is a grid of pixels, and that resolution describes how densely those pixels are packed.
- You know that layers are stacked images you can edit independently.
You do not need any scripting experience. The short script near the end is only there to let you inspect a document.
The canvas and the pixel grid
A Photoshop document is a rectangular canvas filled with pixels. Each pixel stores one value per color channel. In an 8-bit RGB document that means three numbers from 0 to 255, for red, green, and blue.
Three measurements describe the canvas. They are related, but they are not the same thing.
- Pixel dimensions are the width and height in pixels, such as 1920 × 1080. They set how much detail the document holds.
- Resolution is a number in pixels per inch (ppi). It does not change the pixel grid. It only tells a printer how large to make each pixel.
- Document size is the physical print size. It equals pixel dimensions divided by resolution. At 300 ppi, 1920 × 1080 pixels prints at 6.4 × 3.6 inches. At 72 ppi, the same pixels print at about 26.7 × 15 inches.
Changing resolution with resampling turned off, in Image > Image Size, changes only the document size. Changing pixel dimensions with resampling on makes Photoshop invent or discard pixels. Screens ignore ppi entirely. A 1920-pixel-wide image fills 1920 screen pixels at any ppi setting.
Canvas size versus image size
Image Size scales the pixels along with the canvas. Canvas Size changes the canvas and leaves the pixels alone. Making the canvas smaller crops the image. Making it larger adds empty area filled with the background color, or with transparency if the layer allows it. Many "my export is the wrong size" problems come from using one command when the other was needed.
What a document holds in memory
While a document is open, Photoshop holds more than a flat picture. The working document can contain:
- Pixel layers, each with its own pixels and optional transparency.
- Layer masks, adjustment layers, layer styles, and blending settings.
- Smart objects, which embed a source image or a linked file so you can transform it non-destructively.
- Channels, including alpha channels used for saved selections.
- A color mode, bit depth, and an embedded color profile.
- A History panel with your recent steps.
All of this costs memory. You can estimate the uncompressed size of one full-canvas layer like this:
bytes = width x height x channels x bytes per channelA flat 1920 × 1080 RGB image at 8 bits per channel is 1920 × 1080 × 3 = 6,220,800 bytes, about 5.9 MB. A layer with transparency adds an alpha channel, which makes four channels and about 7.9 MB per full-canvas layer. Twenty such layers take roughly 160 MB. Switching the same document to 16 bits per channel doubles every figure. Photoshop also uses scratch disks, which are temporary space on your drive, when memory runs short.
The size of the file on disk is a different number. Each format compresses and discards data in its own way. A JPEG of this document might be a few hundred kilobytes, while the open document uses tens of megabytes of memory.
The file lifecycle
A document moves through the same stages every time you work.
Stage 1: create or open
File > New builds a blank document from settings you choose: size, resolution, color mode, and background. File > Open reads an existing file from disk, decodes it, and builds a document from its contents. Both commands produce the same kind of object, an editable document in memory.
What you get on open depends on the file format:
| Source file | What opens |
|---|---|
| PSD | Full document: layers, masks, smart objects, and the saved profile |
| JPEG | One flat layer named Background. Photoshop decodes the JPEG into pixels |
| PNG | One flat layer. If the PNG has transparency, the layer is not locked as a Background, so the transparency stays |
Opening a file does not edit it. The original file on disk stays untouched until you save over it.
Stage 2: edit in memory
Every brush stroke, layer move, and filter changes only the in-memory document. The title bar shows the document name, the zoom level, and the color mode with bit depth. An asterisk after the name means there are changes not yet saved to disk. Closing Photoshop or the document at that point asks whether to save.
The History panel is also memory-only. It is not stored in a PSD file and is not part of any export. Do not treat it as a backup.
Stage 3: save or export
Saving converts the working document into a file in a chosen format. Two facts matter here:
- A format can only store what it supports. JPEG cannot store layers or transparency. Saving to JPEG flattens a copy of your work into a single opaque image.
- The document stays open as it was. Photoshop warns about lost features, but your in-memory layers are not destroyed unless you flatten them yourself.
A related gotcha: after you choose Save As with a lossy format, the document can become linked to that JPEG file name. If you keep editing and press Save, you overwrite the JPEG again, with another round of lossy compression. Keep your layered PSD as the master and treat other formats as outputs.
Inspecting a document with a script
You can see the properties discussed above in any open document. This ExtendScript runs through File > Scripts > Browse. It reports pixel size, resolution, mode, bit depth, layer count, and whether the document has unsaved changes.
// ExtendScript: report the key properties of the active document
var doc = app.activeDocument;
var info = [
"Name: " + doc.name,
"Size: " + doc.width.as("px") + " x " + doc.height.as("px") + " px",
"Resolution: " + doc.resolution + " ppi",
"Mode: " + doc.mode,
"Bit depth: " + doc.bitsPerChannel,
"Top-level layers: " + doc.layers.length,
"Saved since last change: " + doc.saved
];
alert(info.join("\n"));The call doc.width.as("px") matters. doc.width returns a value in the current ruler units, so the number would change if your preferences use inches or centimeters. Converting to pixels gives a stable result.
Common mistakes
- Confusing ppi with pixel count. Raising resolution from 72 to 300 ppi without resampling does not add detail. It only shrinks the print size.
- Enlarging a small image. Resampling up spreads existing pixels over more area and makes the image softer. It does not recover detail.
- Choosing the wrong size at creation. Create the document at the size you will deliver, or larger. Shrinking later is safe. Enlarging is not.
- Assuming the file on disk matches what you see. The file holds only what its format supports. Reopen an exported file to check it.
- Working from a flattened file. If a JPEG opened and you continue to edit, you are editing decoded pixels with no layers behind them. Go back to the PSD if you have one.
Exercise
You open a 4000 × 3000 pixel JPEG at 300 ppi. You add three text layers and a color adjustment layer, then use File > Save. Photoshop shows a JPEG Options dialog. (a) What is the print size at 300 ppi? (b) Why can your layers not be stored in this file? (c) What should you do to keep the layers editable?
Show answer
(a) 4000 / 300 = 13.33 inches wide and 3000 / 300 = 10 inches tall. (b) JPEG stores only a single flat, opaque pixel grid. It has no place for separate layers, so saving flattens the result and the layers are lost from the file. (c) Use File > Save As and choose Photoshop (PSD) before closing, so the layers, masks, and adjustment layer are stored in a PSD. You can then export the JPEG as a separate output.