Image resizing in ProcessWire tends to be done on a PageImage
object. But what if you wish to manually create and resize an image? To do this you need to create an ImageSizer
object instead. Use the following function to accomplish this.
function pwCreateDuplicateAdjustableImage($src, $dest) {
if (file_exists($src) === false) {
return false;
}
// Duplicate the file
\ProcessWire\wire('files')->copy($src, $dest);
// See https://processwire.com/talk/topic/26113-resize-image-manually/?do=findComment&comment=217464 for why this is needed
$dest = realpath($dest);
return new \ProcessWire\ImageSizer($dest);
}
// Example
$img = pwCreateDuplicateAdjustableImage('./image-1.png', './image-2.png');
$img->resize(800, 600); // Or any function from https://processwire.com/api/ref/image-sizer/
Tim Bennett is a freelance web designer from Leeds. He has a First Class Honours degree in Computing from
Leeds Metropolitan University and currently runs his own one-man web design company, Texelate.