Generate missing photo sizes in Piwigo

Having deployed Piwigo behind Naxsi web application firewall, I am not able to generate multiple photo sizes (Administration > Photos > Batch Manager > Generate multiple size images) for very many photos at a time. I want to keep Naxsi as tight as possible so I decided to generate the missing photo sizes with a workaround: Calling web services manually from shell. First of all I need to login and save session cookie:

wget --keep-session-cookies --save-cookies cookies.txt --delete-after --post-data="username=Admin&password=*****" ""

You should see in your current directory a new file cookies.txt created. Once logged in, let’s fetch missing derivatives, extract the URLs from the resulting JSON file and access them – this will get them generated on the webserver. Since the web service call returns only a limited number of URLs, we will loop until we generate all missing derivatives (photo sizes):

wget --load-cookies cookies.txt -nv -O missing.json ""
while [ `wc -c missing.json | cut -f 1 -d ' '` -gt 50 ]
  sed -e 's/[\\\"]//g' \
  -e 's/{stat:ok,result:{next_page:[0-9]*,urls:\[//' \
  -e 's/{stat:ok,result:{urls:\[//' \
  -e 's/\]}}/\n/' \
  -e 's/,/\n/g' \
  -e 's/\&b=[0-9]*//g' missing.json | \
  while read line ; do
    wget -nv -O /dev/null $line
  wget --load-cookies cookies.txt -nv -O missing.json ""



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s