Skip to content

Commit

Permalink
feature 885 added: pwg.images.add web API method now supports additional
Browse files Browse the repository at this point in the history
high resolution format.


git-svn-id: http://piwigo.org/svn/trunk@2670 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
plegall committed Oct 5, 2008
1 parent 0bdc6a5 commit b53cddb
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
45 changes: 41 additions & 4 deletions include/ws_functions.inc.php
Expand Up @@ -950,7 +950,7 @@ function ws_images_add($params, &$service)
// check dumped file md5sum against expected md5sum
$dumped_md5 = md5_file($file_path);
if ($dumped_md5 != $params['file_sum']) {
return new PwgError(500, 'file transfert failed');
return new PwgError(500, 'file transfer failed');
}

// thumbnail directory is a subdirectory of the photo file, hard coded
Expand Down Expand Up @@ -980,11 +980,42 @@ function ws_images_add($params, &$service)
// check dumped thumbnail md5
$dumped_md5 = md5_file($thumbnail_path);
if ($dumped_md5 != $params['thumbnail_sum']) {
return new PwgError(500, 'thumbnail transfert failed');
return new PwgError(500, 'thumbnail transfer failed');
}

// fwrite($fh_log, 'output: '.md5_file($file_path)."\n");
// fwrite($fh_log, 'output: '.md5_file($thumbnail_path)."\n");
// high resolution
if (isset($params['high_content']))
{
// high resolution directory is a subdirectory of the photo file, hard
// coded "pwg_high"
$high_dir = $upload_dir.'/pwg_high';
if (!is_dir($high_dir)) {
umask(0000);
mkdir($high_dir, 0777);
}

// high resolution path, same name as web size file
$high_path = sprintf(
'%s/%s.%s',
$high_dir,
$filename_wo_ext,
'jpg'
);

// dump the high resolution file
$fh_high = fopen($high_path, 'w');
fwrite($fh_high, base64_decode($params['high_content']));
fclose($fh_high);
chmod($high_path, 0644);

// check dumped thumbnail md5
$dumped_md5 = md5_file($high_path);
if ($dumped_md5 != $params['high_sum']) {
return new PwgError(500, 'high resolution transfer failed');
}

$high_filesize = floor(filesize($high_path)/1024);
}

list($width, $height) = getimagesize($file_path);

Expand Down Expand Up @@ -1017,6 +1048,12 @@ function ws_images_add($params, &$service)
}
}

if (isset($params['high_content']))
{
$insert['has_high'] = 'true';
$insert['high_filesize'] = $high_filesize;
}

include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
mass_inserts(
IMAGES_TABLE,
Expand Down
8 changes: 7 additions & 1 deletion tools/piwigo_remote.pl
Expand Up @@ -6,11 +6,12 @@
use JSON;
use LWP::UserAgent;
use Getopt::Long;
use Encode qw/is_utf8 decode/;

my %opt = ();
GetOptions(
\%opt,
qw/action=s file=s thumbnail=s categories=s define=s%/
qw/action=s file=s thumbnail=s high=s categories=s define=s%/
);

our $ua = LWP::UserAgent->new;
Expand Down Expand Up @@ -62,6 +63,11 @@
categories => $opt{categories},
};

if (defined $opt{high}) {
$form->{high_content} = encode_base64(read_file($opt{high}));
$form->{high_sum} = file_md5_hex($opt{high});
}

foreach my $key (keys %{ $opt{define} }) {
$form->{$key} = $opt{define}{$key};
}
Expand Down
2 changes: 2 additions & 0 deletions ws.php
Expand Up @@ -180,6 +180,8 @@ function ws_addDefaultMethods( $arr )
'file_sum' => array(),
'thumbnail_content' => array(),
'thumbnail_sum' => array(),
'high_content' => array('default' => null),
'high_sum' => array('default' => null),
'name' => array('default' => null),
'author' => array('default' => null),
'date_creation' => array('default' => null),
Expand Down

0 comments on commit b53cddb

Please sign in to comment.