Put the pixel width and height into your PNG filenames by reading the dimensions stored in each file’s header and writing a named copy to a new folder. Preview can confirm the dimensions and open the resulting files. A byte comparison then establishes that each delivery copy has the same file content as its source. The procedure is useful when several exports need to be identifiable in Finder without opening each one.
The sample converts the names of three test exports, including a tiny portrait badge and a wide banner. It leaves the original files in place. Use a source folder you control with ordinary PNG files and a destination beside it. The script previews every proposed name, stops on a header error or conflicting destination name, and asks you to confirm the copy. Keep the source folder stable during the exercise.
Check what the size suffix represents
The PNG specification puts the pixel width and height in the first image header chunk, called IHDR. Each value comes from the file. For a very small portrait badge, one pixel wide and two pixels high, the proposed size is one by two. For a wide banner twenty pixels across and ten high, the suffix says twenty by ten. Read width first so you can distinguish two differently oriented variants with the same pixel count. PNG image header specification.
In Preview, open the original and click the Info button to see the Inspector. Find its general image information and compare width and height measured in pixels. A document’s displayed width, a print measurement, and its DPI can give different numbers. The latter describes the relationship between pixels and physical size. This script uses the actual width and height and preserves the complete PNG content, including embedded image metadata, by copying bytes. Apple’s Preview Inspector guide.
A naming convention of this kind is useful when the consumer selects an asset by its pixel grid. Suppose a package needs both a badge and a banner for separate slots. The suffix quickly tells the recipient which one fits each requirement. It does not record color profile, transparency, or an asset’s approved purpose. Keep the original meaningful stem, and use a separate description or version column if those properties affect the handoff.
Assemble a small input folder
Create two separate working locations under an existing practice folder. Put the ordinary PNG exports inside a folder named Source Images. Leave the planned destination name, Named PNGs, unused. The finished folder needs to sit outside the source tree, even during a trial. If a tool created an empty folder with the destination’s proposed name, choose a different unused name. The script creates the destination itself after confirmation.
For the example, use a one by two image called Badge.png, a ten by twenty image called banner-portrait.png, and a twenty by ten image called Banner.PNG. You can substitute PNGs you already have if you write down their Inspector dimensions before running the script. Keep the distinctive case of each stem and extension in the source list. The proposed output keeps the stem’s case and uses a lowercase PNG extension for all three copies.
The expected names for the sample are Badge-1x2.png, banner-portrait-10x20.png, and Banner-20x10.png. If your two banners are the same width and height but have distinct version labels, keep those labels in the stems. The size suffix alone cannot distinguish a new export from an older version of the same design. Agree on the naming convention before collecting files from multiple teammates.
The script looks at ordinary files directly inside the source folder and handles PNG extensions without requiring a particular case. It skips subdirectories and symbolic links. Check the input count before you begin if your actual export uses nested folders or Finder shortcuts. A two-level export needs its own deliberate selection of files, because the example will leave those nested entries out. If you are preparing a handoff from a graphic design project, use finished exports in the source folder and preserve the original project separately.
Preview the plan from Terminal
Check that Python 3.9 or later is available. Save the standalone script at the end of this guide as name_pngs.py. Use plain text rather than rich text formatting. Open Terminal in the folder containing the script and substitute your absolute paths. The quotes around each argument keep spaces in folder names intact. The parent of the chosen destination already needs to exist.
python3 name_pngs.py "/absolute/path/to/Source Images" "/absolute/path/to/Named PNGs"
Read the printed mappings before typing COPY. Check the count, pixel dimensions, and spelling of each stem. If a proposed output looks wrong, press Return with an empty answer to leave the exercise before the destination is created. Then compare the corresponding source file with its Inspector values. If Preview reports the expected size but you selected another source folder, rerun with the correct path. A plan from a previous command cannot establish what the current argument resolves to.
Existing names deserve special attention. If one source is already named with a size suffix, the script appends the dimensions again. For example, a true twenty by ten file named Banner-15x10.png yields Banner-15x10-20x10.png. The printed mapping reveals a stale label that would otherwise travel into the new name. Stop and decide which portion is the intended stem. If you need to clean old labels, do it on a scratch selection whose mappings you have reviewed. Always point the script at the intended source, because running it on an earlier delivery creates another suffix.
In a case-sensitive source folder you may be able to store both Badge.png and badge.PNG. If both files have the same dimensions, their proposed names can collide when compared without case. The script stops before making that delivery. Use explicit semantic labels, such as light and dark, in a practice copy to resolve the conflict. If they have different dimensions, their output names can coexist, but a reader may still benefit from more distinct asset labels.
Verify copied files by name, appearance, and bytes
Once the plan looks right, type COPY and open the named directory in Finder. Confirm it contains the expected three items. Open each named copy in Preview, check the displayed pixel dimensions, and inspect the actual image. The script reads the initial header bytes and does not decode the entire source. A damaged file can have a plausible header but fail to open. Preview’s full read is an independent check of what you will deliver.
Use the following comparison for the sample badge. Substitute the absolute source and destination paths used in your run. The comparison is quiet when the contents match. An explicit success message follows a zero exit status. Run the equivalent check for the portrait and banner, using their distinct paths. Compare the complete sets this way for a small delivery.
cmp -s "/absolute/path/to/Source Images/Badge.png" "/absolute/path/to/Named PNGs/Badge-1x2.png" \
&& echo "Badge contents match."
File data and filesystem metadata deserve different checks. Identical data preserves the image and what is encoded inside it. Items such as Finder tags, permissions, or timestamps can be managed separately by the filesystem, and this simple byte-copy path does not aim to duplicate all of them. If an external handoff requires any of those properties, inspect the recipient’s use case before choosing this copy method. Python file-copy functions.
Keep the printed source-to-destination mappings for a batch with several closely named revisions. If someone reports that the banner should have a different size, the mapping and original file let you identify which export was used. You can fix the export or choose a different input and create a new output directory without overwriting either the original or the previous delivery.
Handle a rejected or interrupted copy
If the script names an invalid header, open that exact file in Preview and find out whether it is a PNG. Renaming another format to a PNG extension does not change its bytes. Export a genuine PNG from its source application to a new location, inspect it, and then decide whether to include it. If the original fails to decode, obtain a clean export rather than masking the failure with a new name.
An interrupted copy can leave a destination with only some files. Treat it as an incomplete batch and preserve it outside the delivery while you investigate the error. Check the number of copied files against the printed plan and run the content comparisons you intended. Use a fresh output folder for a retry after resolving access or free space. The exclusive creation mode stops a copy from silently overwriting a file, which makes these failure states visible.
Take care around actively exported folders. If an image editor updates a source between reading its header and copying its contents, the delivered filename can describe the earlier dimensions. Run from a stable staged folder, inspect the resulting image dimensions, and keep the file set available until the handoff is accepted. A successful result is a set of expected names, matching dimensions, and matching file bytes for every item you plan to use.
Standalone naming script
# Run in Terminal: python3 name_pngs.py "/path/to/input" "/path/to/new-output"
from pathlib import Path
import os
import shutil
import struct
import sys
source, output = (Path(arg).resolve() for arg in sys.argv[1:])
if not source.is_dir() or output.is_relative_to(source) or output.exists():
raise SystemExit("Use an input directory and a new destination outside it.")
plan = []
for file in sorted(source.iterdir()):
if file.is_symlink() or not file.is_file() or file.suffix.lower() != ".png":
continue
with file.open("rb") as stream:
header = stream.read(24)
if len(header) != 24 or header[:16] != b"\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR":
raise SystemExit(f"Invalid PNG header: {file.name}")
width, height = struct.unpack(">II", header[16:24])
if not width or not height:
raise SystemExit(f"Empty image dimensions: {file.name}")
name = f"{file.stem}-{width}x{height}.png"
plan.append((file, name))
print(file.name, "->", name)
if not plan or len({n.casefold() for _, n in plan}) != len(plan):
raise SystemExit("Empty input or colliding output names.")
if input("Type COPY to create this set: ") != "COPY":
raise SystemExit("Stopped.")
output.mkdir()
for file, name in plan:
with file.open("rb") as src, (output / name).open("xb") as dst:
shutil.copyfileobj(src, dst)
Identify which canvas the size describes
For a transparent badge, the full pixel grid can be much larger than the visible mark. Preview the named copy against a contrasting background if it is difficult to see the transparent border. An expected one by two test simply confirms the orientation. A customer slot that requires the artwork itself to fill a frame needs a separate visual check of margins and transparency. Record the canvas dimensions and intended asset use separately when those distinctions matter. This keeps a correct filename from silently standing in for a layout decision.