Announcement

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

Jessie
Member
2016-09-04
31

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
2013-06-12
427

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
2016-09-04
31

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
2013-06-12
427

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
2016-09-04
31

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
2013-06-12
427

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

 

#22 2017-08-20 00:10:53

CalgarySteveWilliams
Member
2017-08-19
7

Re: Generation of custom size thumbnails

Hi,

For some reason, this code does not work under Piwigo 2.9.1

I created another issue under "Themes" before I found this thread.
http://piwigo.org/forum/viewtopic.php?id=28200

I have confirmed that the PersonalPlugin code is running by putting in something that threw an error :)

I am at a loss on how the functions are ever called.  I've added the following line inside the
function bm_gen_custom_derivatives_form()
  $logger->debug('In bm_gen_custom_derivatives_form');^M

This function is what should append the element to the array that is the drop down in the Batch Manager.

Where does it get called from?

Doesn't there need to be an event handler that calls the function to add the element to the array?

I added the following line to my Personal Plugin code:

add_event_handler('loc_end_element_set_global', 'bm_gen_custom_derivatives_form');

And now the new selection shows up in the menu, but when I try to run it, nothing happens.  I look at my web server logs and there's no URL being requested from the server, so not sure what's going on.

Further troubleshooting :(

Thanks,
Steve Williams

Offline

 

#23 2017-08-20 01:29:21

CalgarySteveWilliams
Member
2017-08-19
7

Re: Generation of custom size thumbnails

Hi,

Just to document things...  I added another event handler (to Personal Plugin) to actually trigger the action.
add_event_handler('element_set_global_action', 'bm_gen_custom_derivatives_action');

The script is now actually triggering from the Batch Manager.  Yeah.

Sadly, the script is throwing an error:
Notice: Trying to get property of non-object in /piwigo/plugins/PersonalPlugin/main.inc.php on line 38

Line 38 corresponds to:
        $sq_url = $result->result->derivatives->square->url;

Here is my entire Personal Plugin:

<?php
/*
Plugin Name: Personal Plugin
Version: 1.0
Description: Personal Plugin
Plugin URI: http://piwigo.org
Author:
Author URI:
*/

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);
      }
    }
  }
}

add_event_handler('loc_end_element_set_global', 'bm_gen_custom_derivatives_form');
add_event_handler('element_set_global_action', 'bm_gen_custom_derivatives_action');


?>

Offline

 

#24 2017-09-08 13:30:49

miblo69
Member
Stockholm, Sweden
2012-06-05
27

Re: Generation of custom size thumbnails

I have issues too, related to Batch Manager. Specifically I get errors when using different locales that I have set in config.ini.php. It is probably completely unrelated to your issue, but there is something in Batch Manager that doesn't like International characters or different encodings.

Just a thought...

Offline

 

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2024 · Contact