#!/usr/bin/php ', $prog); println('Optional arguments:'); println(' -d turn debug output on.'); println('Mandatory arguments:'); println(' input the input filename, a JPEG image.'); println(' output filename for saving the changed image.'); println(' scale scale factor, say 0.5 to resize to half the ' . 'original size.'); exit(1); } /* The input file is now loaded into a PelJpeg object. */ println('Reading file "%s".', $input); $input_jpeg = new PelJpeg($input); /* * The input image is already loaded, so we can reuse the bytes stored * in $input_jpeg when creating the Image resource. */ $original = ImageCreateFromString($input_jpeg->getBytes()); $original_w = ImagesX($original); $original_h = ImagesY($original); $scaled_w = $original_w * $scale; $scaled_h = $original_h * $scale; /* Now create the scaled image. */ $scaled = ImageCreateTrueColor($scaled_w, $scaled_h); ImageCopyResampled($scaled, $original, 0, 0, 0, 0, $scaled_w, $scaled_h, $original_w, $original_h); /* * We want the raw JPEG data from $scaled. Luckily, one can create a * PelJpeg object from an image resource directly: */ $output_jpeg = new PelJpeg($scaled); /* Retrieve the original Exif data in $jpeg (if any). */ $exif = $input_jpeg->getExif(); /* If no Exif data was present, then $exif is null. */ if ($exif != null) { $output_jpeg->setExif($exif); } /* We can now save the scaled image. */ println('Writing file "%s".', $output); $output_jpeg->saveFile($output);