Jump to content

Helpful little script that copies images from pages to a folder and resizes them.


KarlvonKarton
 Share

Recommended Posts

For a customer I needed a bunch of pictures to make a mosaic in Photoshop (cropped as a square) 😉
20 lines of ProcessWire  "et voila": a folder full of first pictures of every page from a certain template.
 

<?php namespace ProcessWire;
// boot api
include('index.php');
// find estates from web database
$estates = $pages->find("template=archief-pand");
// if estates count not zero
if(count($estates)){
    // loop over estates ($e is single estate)
    foreach($estates as $e){
        // if images not null
        if(count($e->images)){
            // get first image of estate gallery
            $firstPic = $e->images->first();
            // resize and crop image to square 800x800px
            $firstPic = $firstPic->size(800,800);
            // if picture not null then copy picture to folder propics
            if(!empty($firstPic)) copy($_SERVER['DOCUMENT_ROOT'].$firstPic->url, $_SERVER['DOCUMENT_ROOT'].'/propics/'.$firstPic);
        }
    }
}



 

  • Like 6
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...