Announcement

  •  » Extensions
  •  » Thumbnail management (creating new, deleting orphans)

#1 2017-06-07 22:15:03

windracer
Member
St. Pete, FL
2014-12-28
455

Thumbnail management (creating new, deleting orphans)

I'm writing a plugin that moves photos between physical albums, preserving the metadata. I've got the basics working: when editing a photo (or video) that's already in a physical album, select the new Move tab, pick a target physical album, click Move:

http://piwigo.org/forum/showimage.php?pid=167739&filename=ppm-ui.png

The file on disk is moved from the source directory to the target and the IMAGES_TABLE and IMAGE_CATEGORY_TABLE tables are updated accordingly. This preserves all the tags, description, etc. etc.

What I'm trying to figure out now is how to manage the thumbnails, specifically:

- clean up the thumbnails left behind for the image's original location
- create thumbnails for the image's new location (I know the new thumbnails will be auto-generated when the photo is accessed for the first time, but ideally I'd create those as part of the move)

Poking around in the Piwigo functions (like the uploader), I found delete_element_derivatives. Would this handle the thumbnails (-cu, -me, -sq, -th, etc.)? If so, would it also handle the pwg_representatives (i.e., thumbnails for videos created by videojs)?

Any suggestions on how to properly handle this or the creation of the new thumbnails?

Right now the plugin only works on a single photo but I'd like to eventually add it to Batch Manager as well ... maybe version 2.0. :)

Thanks!

Piwigo version: 2.9.0
PHP version: 7.0.18-0ubuntu0.17.04.1
MySQL version: 5.7.18-0ubuntu0.17.04.1

Last edited by windracer (2017-06-07 22:15:46)

Offline

 

#2 2017-06-08 10:49:16

flop25
Piwigo Team
2006-07-06
7037

Re: Thumbnail management (creating new, deleting orphans)

Hello
delete_element_derivatives is removing only the generated resized pictures (-cu, -me, -sq, -th, etc.) by default all

for the representative, you could move it with the original object (representative_ext original_to_representative( $path, $infos['representative_ext']) ) ; you could also move the derivative since the tree is the same as the physical one, and avoid the issue of recreating it


To get a better help : Politeness like Hello-A link-Your past actions precisely described
Check my extensions : more than 30 available
who I am and what I do : http://fr.gravatar.com/flop25
My gallery : an illustration of how to integrate Piwigo in your website

Offline

 

#3 2017-06-08 17:38:18

eliz82
Member
Romania
2016-04-27
281

Re: Thumbnail management (creating new, deleting orphans)

great plugin, if you make it work with batch manager i will use it

Offline

 

#4 2017-06-08 17:52:04

windracer
Member
St. Pete, FL
2014-12-28
455

Re: Thumbnail management (creating new, deleting orphans)

flop25 wrote:

Hello
delete_element_derivatives is removing only the generated resized pictures (-cu, -me, -sq, -th, etc.) by default all

Thanks for the confirmation. I'll use that to remove the thumbnails/resizes from the source directory.

flop25 wrote:

for the representative, you could move it with the original object (representative_ext original_to_representative( $path, $infos['representative_ext']) ) ; you could also move the derivative since the tree is the same as the physical one, and avoid the issue of recreating it

Ok, I'll look into this. Thanks for the tips! Sounds like I'm on the right path.

Offline

 

#5 2017-06-08 21:39:34

windracer
Member
St. Pete, FL
2014-12-28
455

Re: Thumbnail management (creating new, deleting orphans)

I've got the representative handling working. Had to do a little more than I originally thought because the pwg_representative folder might not exist yet in the destination so I have to create it. And then I also wanted to remove the pwg_representative folder from the source if it was empty after the move.

Now on to the derivatives ...

Offline

 

#6 2017-06-09 01:48:13

windracer
Member
St. Pete, FL
2014-12-28
455

Re: Thumbnail management (creating new, deleting orphans)

Grrr ... just realized that representatives can also have derivatives. So in addition to the pwg_representative folder in the physical directory/album, there's also in the derivatives folder under /_data/i/...etc.

Offline

 

#7 2017-06-09 05:47:31

windracer
Member
St. Pete, FL
2014-12-28
455

Re: Thumbnail management (creating new, deleting orphans)

Ok, I think I've manage to cover all the bases. The plugin handles representatives (and their derivatives) and all other derivatives, so no orphans and no need to re-generate. I want to do some more testing and then I'll try and publish my first plugin!

Offline

 

#8 2017-06-10 03:58:16

windracer
Member
St. Pete, FL
2014-12-28
455

Re: Thumbnail management (creating new, deleting orphans)

Offline

 

#9 2017-06-10 05:46:38

ddtddt
Piwigo Team
Quetigny - France
2007-07-27
7207

Re: Thumbnail management (creating new, deleting orphans)

Hi :-)

Can you add EN file for language support


You love Piwigo so don't hesitate to participate, learn more on the "Contribute to Piwigo" page. If you don't have much time for contribution, you can also help the project with a donation.

Offline

 

#10 2017-06-10 06:02:11

windracer
Member
St. Pete, FL
2014-12-28
455

Re: Thumbnail management (creating new, deleting orphans)

Can you point me to instructions on how to do that? Everything is in English already.

Offline

 

#11 2017-06-10 06:13:50

ddtddt
Piwigo Team
Quetigny - France
2007-07-27
7207

Re: Thumbnail management (creating new, deleting orphans)

Hi :-)

in main.inc.php add function to load language

Code:

add_event_handler('loading_lang', 'physical_photo_move_loading_lang');    
function physical_photo_move_loading_lang(){
  load_language('plugin.lang', PPM_PATH);
}

add folder 'language'

in forder language add folder 'en_UK'

in forder en_UK add files

description.txt and plugin.lang.php

description.txt ->

Code:

Move a photo (the actual file) from one physical album to another, preserving all metadata.

plugin.lang.php ->

Code:

<?php
$lang['Move Photo'] = 'Move Photo';
$lang['Current physical album:'] = 'Current physical album:';
$lang['Current file location:'] = 'Current file location:';
........
?>

You love Piwigo so don't hesitate to participate, learn more on the "Contribute to Piwigo" page. If you don't have much time for contribution, you can also help the project with a donation.

Offline

 

#12 2017-06-10 18:01:41

windracer
Member
St. Pete, FL
2014-12-28
455

Re: Thumbnail management (creating new, deleting orphans)

Ok, seems straightforward enough. I already had the load_language in there, but no corresponding add_event or the language files, obviously.

So in plugin.lang.php, I should include a line for every @translate in my plugin, right?

Offline

 

#13 2017-06-10 18:03:50

flop25
Piwigo Team
2006-07-06
7037

Re: Thumbnail management (creating new, deleting orphans)

Yes


To get a better help : Politeness like Hello-A link-Your past actions precisely described
Check my extensions : more than 30 available
who I am and what I do : http://fr.gravatar.com/flop25
My gallery : an illustration of how to integrate Piwigo in your website

Offline

 

#14 2017-06-10 18:13:23

windracer
Member
St. Pete, FL
2014-12-28
455

Re: Thumbnail management (creating new, deleting orphans)

Also, it looks like I should redo my @translate lines and use variable names to make the lines in plugin.inc.php shorter. In other words this:

Code:

$lang['CURR_PHYS_ALBUM'] = 'Current physical album:';

instead of this:

Code:

$lang['Current physical album:'] = 'Current physical album:';

And then I'd have to add an en_US language folder with these files too since that's my own default language. And I'm guessing if I didn't, I end up seeing 'CURR_PHYS_ALBUM' on the page instead of the en_US translation.

Thank you!

Offline

 

#15 2017-06-10 18:17:42

flop25
Piwigo Team
2006-07-06
7037

Re: Thumbnail management (creating new, deleting orphans)

Absolutely
You're welcome


To get a better help : Politeness like Hello-A link-Your past actions precisely described
Check my extensions : more than 30 available
who I am and what I do : http://fr.gravatar.com/flop25
My gallery : an illustration of how to integrate Piwigo in your website

Offline

 
  •  » Extensions
  •  » Thumbnail management (creating new, deleting orphans)

Board footer

Powered by FluxBB

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