Piwigo.org

You are not logged in. (Register / Login)

Announcement

#16 2016-09-04 21:00:55

Jessie
Member
Registered: 2016-09-04
Posts: 29

Re: Generation of custom size thumbnails

Too bad.

Is it possible for me to generate the thumbnails manually in the piwigo directory ?
I can write a Python script easily if I have the specs of what I have to do.

Thanks !

Offline

 

#17 2016-09-05 08:13:47

teekay
Member
Registered: 2013-06-12
Posts: 224

Re: Generation of custom size thumbnails

Jessie wrote:

Too bad.

Is it possible for me to generate the thumbnails manually in the piwigo directory ?
I can write a Python script easily if I have the specs of what I have to do.

Thanks !

You could extend the plugin code above to include the basic authentication bits. See for example http://www.hashbangcode.com/blog/using- … tcontents. But of course, that would leave the password stored in clear text in the personal plugin code.

But given that PHP code runs server-side, you also could simply allow localhost/127.0.0.1 unauthenticated access in your .htaccess - that would make more sense.

Offline

 

#18 2016-09-05 17:55:13

Jessie
Member
Registered: 2016-09-04
Posts: 29

Re: Generation of custom size thumbnails

I have tried disabling the HTTP Basic authentication, but I still have the same mistaKe :

Warning: file_get_contents(https://piwigo.example.com/ws.php?forma … mage_id=61): failed to open stream: HTTP request failed! HTTP/1.1 401 Access denied in /var/www/piwigo/plugins/PersonalPlugin/main.inc.php on line 38

I've checked and 'allow_url_fopen' is set to 'Off'.

Should I try other things to make it work ?

Thanks for your help !

Offline

 

#19 2016-09-05 20:07:58

teekay
Member
Registered: 2013-06-12
Posts: 224

Re: Generation of custom size thumbnails

You could try that ini_set patch above. Else the plugin needs to be rewritten using curl instead.

Offline

 

#20 2016-09-05 20:13:08

Jessie
Member
Registered: 2016-09-04
Posts: 29

Re: Generation of custom size thumbnails

Unfortunately it doesn't work, I still got the same error...

Offline

 

#21 2017-03-05 14:17:32

teekay
Member
Registered: 2013-06-12
Posts: 224

Re: Generation of custom size thumbnails

Here's a version of the plugin that uses cURL instead of fopen(). Maybe that one works. Authentication is still untested. It does pass over the pwg_id from the cookie, but maybe a session has to be created explicitly for the web service. It works fine here for public albums.

Code:

function bm_gen_custom_derivatives_form() {
  global $template;
  $template_add = '';
  foreach (array_keys(ImageStdParams::$custom) as $custom) {
    $template_add = $template_add . '<input type="checkbox" name="custom_sizes[]" value="' . $custom . '">' . $custom . '<br />';
  }

  $template->append('element_set_global_plugins_actions', array(
     'ID' => 'GenCustomDerivatives', 
     'NAME' => l10n('Pre-cache custom size derivatives'), 
     'CONTENT' => $template_add,
  ));
}

function bm_gen_custom_derivatives_action($action, $collection) {
  if ($action == 'GenCustomDerivatives'){
    global $page;
    foreach ($collection as $image_id){
      if (isset($_POST['custom_sizes'])) {
        $strCookie = 'pwg_id=' . $_COOKIE['pwg_id'] . '; path=/';
        $ch = curl_init(get_absolute_root_url() .'ws.php?format=json&method=pwg.images.getInfo&image_id=' . $image_id);
        curl_setopt($ch, CURLOPT_REFERER, get_absolute_root_url());
        curl_setopt($ch, CURLOPT_COOKIE, $strCookie );
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $result = json_decode(curl_exec($ch));
        $sq_url = $result->result->derivatives->square->url;

        foreach ($_POST['custom_sizes'] as $size) {
          $url = str_replace('sq.jpg', 'cu_' . $size . '.jpg', $sq_url);
          curl_setopt($ch, CURLOPT_URL, $url);
          curl_exec($ch);
        }
        curl_close($ch);
      }
    }
  }
}

Offline

 

Board footer

Powered by FluxBB

github twitter facebook google+ newsletter Donate Piwigo.org © 2002-2017 · Contact