source: trunk/admin/include/functions_upload.inc.php @ 9952

Last change on this file since 9952 was 9952, checked in by patdenice, 13 years ago

feature:2239
Support GIF format in the upload form (only in GD)

File size: 22.4 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2011 Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
25
26// add default event handler for image and thumbnail resize
27add_event_handler('upload_image_resize', 'pwg_image_resize', EVENT_HANDLER_PRIORITY_NEUTRAL, 7);
28add_event_handler('upload_thumbnail_resize', 'pwg_image_resize', EVENT_HANDLER_PRIORITY_NEUTRAL, 7);
29
30function get_upload_form_config()
31{
32  // default configuration for upload
33  $upload_form_config = array(
34    'websize_resize' => array(
35      'default' => true,
36      'can_be_null' => false,
37      ),
38   
39    'websize_maxwidth' => array(
40      'default' => 800,
41      'min' => 100,
42      'max' => 1600,
43      'pattern' => '/^\d+$/',
44      'can_be_null' => true,
45      'error_message' => l10n('The websize maximum width must be a number between %d and %d'),
46      ),
47 
48    'websize_maxheight' => array(
49      'default' => 600,
50      'min' => 100,
51      'max' => 1200,
52      'pattern' => '/^\d+$/',
53      'can_be_null' => true,
54      'error_message' => l10n('The websize maximum height must be a number between %d and %d'),
55      ),
56 
57    'websize_quality' => array(
58      'default' => 95,
59      'min' => 50,
60      'max' => 100,
61      'pattern' => '/^\d+$/',
62      'can_be_null' => false,
63      'error_message' => l10n('The websize image quality must be a number between %d and %d'),
64      ),
65 
66    'thumb_maxwidth' => array(
67      'default' => 128,
68      'min' => 50,
69      'max' => 300,
70      'pattern' => '/^\d+$/',
71      'can_be_null' => false,
72      'error_message' => l10n('The thumbnail maximum width must be a number between %d and %d'),
73      ),
74 
75    'thumb_maxheight' => array(
76      'default' => 96,
77      'min' => 50,
78      'max' => 300,
79      'pattern' => '/^\d+$/',
80      'can_be_null' => false,
81      'error_message' => l10n('The thumbnail maximum height must be a number between %d and %d'),
82      ),
83 
84    'thumb_quality' => array(
85      'default' => 95,
86      'min' => 50,
87      'max' => 100,
88      'pattern' => '/^\d+$/',
89      'can_be_null' => false,
90      'error_message' => l10n('The thumbnail image quality must be a number between %d and %d'),
91      ),
92 
93    'hd_keep' => array(
94      'default' => true,
95      'can_be_null' => false,
96      ),
97 
98    'hd_resize' => array(
99      'default' => false,
100      'can_be_null' => false,
101      ),
102 
103    'hd_maxwidth' => array(
104      'default' => 2000,
105      'min' => 500,
106      'max' => 20000,
107      'pattern' => '/^\d+$/',
108      'can_be_null' => false,
109      'error_message' => l10n('The high definition maximum width must be a number between %d and %d'),
110      ),
111 
112    'hd_maxheight' => array(
113      'default' => 2000,
114      'min' => 500,
115      'max' => 20000,
116      'pattern' => '/^\d+$/',
117      'can_be_null' => false,
118      'error_message' => l10n('The high definition maximum height must be a number between %d and %d'),
119      ),
120 
121    'hd_quality' => array(
122      'default' => 95,
123      'min' => 50,
124      'max' => 100,
125      'pattern' => '/^\d+$/',
126      'can_be_null' => false,
127      'error_message' => l10n('The high definition image quality must be a number between %d and %d'),
128      ),
129    );
130
131  return $upload_form_config;
132}
133
134/*
135 * automatic fill of configuration parameters
136 */
137function prepare_upload_configuration()
138{
139  global $conf;
140
141  $inserts = array();
142 
143  foreach (get_upload_form_config() as $param_shortname => $param)
144  {
145    $param_name = 'upload_form_'.$param_shortname;
146 
147    if (!isset($conf[$param_name]))
148    {
149      $conf[$param_name] = $param['default'];
150     
151      array_push(
152        $inserts,
153        array(
154          'param' => $param_name,
155          'value' => boolean_to_string($param['default']),
156          )
157        );
158    }
159  }
160 
161  if (count($inserts) > 0)
162  {
163    mass_inserts(
164      CONFIG_TABLE,
165      array_keys($inserts[0]),
166      $inserts
167      );
168  }
169}
170
171function add_uploaded_file($source_filepath, $original_filename=null, $categories=null, $level=null, $image_id=null)
172{
173  // Here is the plan
174  //
175  // 1) move uploaded file to upload/2010/01/22/20100122003814-449ada00.jpg
176  //
177  // 2) if taller than max_height or wider than max_width, move to pwg_high
178  //    + web sized creation
179  //
180  // 3) thumbnail creation from web sized
181  //
182  // 4) register in database
183 
184  // TODO
185  // * check md5sum (already exists?)
186 
187  global $conf, $user;
188
189  $md5sum = md5_file($source_filepath);
190  $file_path = null;
191 
192  if (isset($image_id))
193  {
194    // we are performing an update
195    $query = '
196SELECT
197    path
198  FROM '.IMAGES_TABLE.'
199  WHERE id = '.$image_id.'
200;';
201    $result = pwg_query($query);
202    while ($row = pwg_db_fetch_assoc($result))
203    {
204      $file_path = $row['path'];
205    }
206   
207    if (!isset($file_path))
208    {
209      die('['.__FUNCTION__.'] this photo does not exist in the database');
210    }
211
212    // delete all physical files related to the photo (thumbnail, web site, HD)
213    delete_element_files(array($image_id));
214  }
215  else
216  {
217    // this photo is new
218   
219    // current date
220    list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
221    list($year, $month, $day) = preg_split('/[^\d]/', $dbnow, 4);
222 
223    // upload directory hierarchy
224    $upload_dir = sprintf(
225      PHPWG_ROOT_PATH.$conf['upload_dir'].'/%s/%s/%s',
226      $year,
227      $month,
228      $day
229      );
230
231    // compute file path
232    $date_string = preg_replace('/[^\d]/', '', $dbnow);
233    $random_string = substr($md5sum, 0, 8);
234    $filename_wo_ext = $date_string.'-'.$random_string;
235    $file_path = $upload_dir.'/'.$filename_wo_ext.'.';
236
237    list($width, $height, $type) = getimagesize($source_filepath);
238    if (IMAGETYPE_PNG == $type)
239    {
240      $file_path.= 'png';
241    }
242    elseif (IMAGETYPE_GIF == $type)
243    {
244      $file_path.= 'gif';
245    }
246    else
247    {
248      $file_path.= 'jpg';
249    }
250
251    prepare_directory($upload_dir);
252  }
253
254  if (is_uploaded_file($source_filepath))
255  {
256    move_uploaded_file($source_filepath, $file_path);
257  }
258  else
259  {
260    copy($source_filepath, $file_path);
261  }
262
263  if ($conf['upload_form_websize_resize']
264      and need_resize($file_path, $conf['upload_form_websize_maxwidth'], $conf['upload_form_websize_maxheight']))
265  {
266    $high_path = file_path_for_type($file_path, 'high');
267    $high_dir = dirname($high_path);
268    prepare_directory($high_dir);
269   
270    rename($file_path, $high_path);
271    $high_infos = pwg_image_infos($high_path);
272   
273    trigger_event(
274      'upload_image_resize',
275      false,
276      $high_path,
277      $file_path,
278      $conf['upload_form_websize_maxwidth'],
279      $conf['upload_form_websize_maxheight'],
280      $conf['upload_form_websize_quality'],
281      false
282      );
283
284    if (is_imagick())
285    {
286      if ($conf['upload_form_hd_keep'])
287      {
288        if ($conf['upload_form_hd_resize'])
289        {
290          $need_resize = need_resize($high_path, $conf['upload_form_hd_maxwidth'], $conf['upload_form_hd_maxheight']);
291       
292          if ($need_resize)
293          {
294            pwg_image_resize(
295              false,
296              $high_path,
297              $high_path,
298              $conf['upload_form_hd_maxwidth'],
299              $conf['upload_form_hd_maxheight'],
300              $conf['upload_form_hd_quality'],
301              false
302              );
303            $high_infos = pwg_image_infos($high_path);
304          }
305        }
306      }
307      else
308      {
309        unlink($high_path);
310        $high_infos = null;
311      }
312    }
313  }
314
315  $file_infos = pwg_image_infos($file_path);
316 
317  $thumb_path = file_path_for_type($file_path, 'thumb');
318  $thumb_dir = dirname($thumb_path);
319  prepare_directory($thumb_dir);
320 
321  trigger_event(
322    'upload_thumbnail_resize',
323    false,
324    $file_path,
325    $thumb_path,
326    $conf['upload_form_thumb_maxwidth'],
327    $conf['upload_form_thumb_maxheight'],
328    $conf['upload_form_thumb_quality'],
329    true
330    );
331 
332  $thumb_infos = pwg_image_infos($thumb_path);
333
334  if (isset($image_id))
335  {
336    $update = array(
337      'id' => $image_id,
338      'file' => pwg_db_real_escape_string(isset($original_filename) ? $original_filename : basename($file_path)),
339      'filesize' => $file_infos['filesize'],
340      'width' => $file_infos['width'],
341      'height' => $file_infos['height'],
342      'md5sum' => $md5sum,
343      'added_by' => $user['id'],
344      );
345   
346    if (isset($high_infos))
347    {
348      $update['has_high'] = 'true';
349      $update['high_filesize'] = $high_infos['filesize'];
350    }
351    else
352    {
353      $update['has_high'] = 'false';
354      $update['high_filesize'] = null;
355    }
356
357    if (isset($level))
358    {
359      $update['level'] = $level;
360    }
361
362    mass_updates(
363      IMAGES_TABLE,
364      array(
365        'primary' => array('id'),
366        'update' => array_keys($update)
367        ),
368      array($update)
369      );
370  }
371  else
372  {
373    // database registration
374    $insert = array(
375      'file' => pwg_db_real_escape_string(isset($original_filename) ? $original_filename : basename($file_path)),
376      'date_available' => $dbnow,
377      'tn_ext' => 'jpg',
378      'path' => preg_replace('#^'.preg_quote(PHPWG_ROOT_PATH).'#', '', $file_path),
379      'filesize' => $file_infos['filesize'],
380      'width' => $file_infos['width'],
381      'height' => $file_infos['height'],
382      'md5sum' => $md5sum,
383      'added_by' => $user['id'],
384      );
385
386    if (isset($high_infos))
387    {
388      $insert['has_high'] = 'true';
389      $insert['high_filesize'] = $high_infos['filesize'];
390    }
391
392    if (isset($level))
393    {
394      $insert['level'] = $level;
395    }
396 
397    mass_inserts(
398      IMAGES_TABLE,
399      array_keys($insert),
400      array($insert)
401      );
402 
403    $image_id = pwg_db_insert_id(IMAGES_TABLE);
404  }
405
406  if (isset($categories) and count($categories) > 0)
407  {
408    associate_images_to_categories(
409      array($image_id),
410      $categories
411      );
412  }
413 
414  // update metadata from the uploaded file (exif/iptc)
415  if ($conf['use_exif'] and !function_exists('read_exif_data'))
416  {
417    $conf['use_exif'] = false;
418  }
419  update_metadata(array($image_id=>$file_path));
420
421  invalidate_user_cache();
422
423  return $image_id;
424}
425
426function prepare_directory($directory)
427{
428  if (!is_dir($directory)) {
429    if (substr(PHP_OS, 0, 3) == 'WIN')
430    {
431      $directory = str_replace('/', DIRECTORY_SEPARATOR, $directory);
432    }
433    umask(0000);
434    $recursive = true;
435    if (!@mkdir($directory, 0777, $recursive))
436    {
437      die('[prepare_directory] cannot create directory "'.$directory.'"');
438    }
439  }
440
441  if (!is_writable($directory))
442  {
443    // last chance to make the directory writable
444    @chmod($directory, 0777);
445
446    if (!is_writable($directory))
447    {
448      die('[prepare_directory] directory "'.$directory.'" has no write access');
449    }
450  }
451
452  secure_directory($directory);
453}
454
455function need_resize($image_filepath, $max_width, $max_height)
456{
457  // TODO : the resize check should take the orientation into account. If a
458  // rotation must be applied to the resized photo, then we should test
459  // invert width and height.
460  list($width, $height) = getimagesize($image_filepath);
461 
462  if ($width > $max_width or $height > $max_height)
463  {
464    return true;
465  }
466
467  return false;
468}
469
470function get_resize_dimensions($width, $height, $max_width, $max_height, $rotation=null)
471{
472  $rotate_for_dimensions = false;
473  if (isset($rotation) and in_array(abs($rotation), array(90, 270)))
474  {
475    $rotate_for_dimensions = true;
476  }
477
478  if ($rotate_for_dimensions)
479  {
480    list($width, $height) = array($height, $width);
481  }
482 
483  $ratio_width  = $width / $max_width;
484  $ratio_height = $height / $max_height;
485  $destination_width = $width; 
486  $destination_height = $height;
487 
488  // maximal size exceeded ?
489  if ($ratio_width > 1 or $ratio_height > 1)
490  {
491    if ($ratio_width < $ratio_height)
492    { 
493      $destination_width = ceil($width / $ratio_height);
494      $destination_height = $max_height;
495    }
496    else
497    { 
498      $destination_width = $max_width; 
499      $destination_height = ceil($height / $ratio_width);
500    }
501  }
502
503  if ($rotate_for_dimensions)
504  {
505    list($destination_width, $destination_height) = array($destination_height, $destination_width);
506  }
507 
508  return array(
509    'width' => $destination_width,
510    'height'=> $destination_height,
511    );
512}
513
514function pwg_image_resize($result, $source_filepath, $destination_filepath, $max_width, $max_height, $quality, $strip_metadata=false)
515{
516  if ($result !== false)
517  {
518    //someone hooked us - so we skip
519    return $result;
520  }
521
522  $extension = strtolower(get_extension($source_filepath));
523
524  if (is_imagick() and $extension != 'gif')
525  {
526    return pwg_image_resize_im($source_filepath, $destination_filepath, $max_width, $max_height, $quality, $strip_metadata);
527  }
528  else
529  {
530    return pwg_image_resize_gd($source_filepath, $destination_filepath, $max_width, $max_height, $quality);
531  }
532}
533
534function pwg_image_resize_gd($source_filepath, $destination_filepath, $max_width, $max_height, $quality)
535{
536  if (!function_exists('gd_info'))
537  {
538    return false;
539  }
540
541  $gd_info = gd_info();
542
543  // extension of the picture filename
544  $extension = strtolower(get_extension($source_filepath));
545
546  $source_image = null;
547  if (in_array($extension, array('jpg', 'jpeg')))
548  {
549    $source_image = imagecreatefromjpeg($source_filepath);
550  }
551  else if ($extension == 'png')
552  {
553    $source_image = imagecreatefrompng($source_filepath);
554  }
555  elseif ($extension == 'gif' and $gd_info['GIF Read Support'] and $gd_info['GIF Create Support'])
556  {
557    $source_image = imagecreatefromgif($source_filepath);
558  }
559  else
560  {
561    die('[GD] unsupported file extension');
562  }
563
564  $rotation = null;
565  if (function_exists('imagerotate'))
566  {
567    $rotation = get_rotation_angle($source_filepath);
568  }
569 
570  // width/height
571  $source_width  = imagesx($source_image); 
572  $source_height = imagesy($source_image);
573 
574  $resize_dimensions = get_resize_dimensions($source_width, $source_height, $max_width, $max_height, $rotation);
575
576  // testing on height is useless in theory: if width is unchanged, there
577  // should be no resize, because width/height ratio is not modified.
578  if ($resize_dimensions['width'] == $source_width and $resize_dimensions['height'] == $source_height)
579  {
580    // the image doesn't need any resize! We just copy it to the destination
581    copy($source_filepath, $destination_filepath);
582    return true;
583  }
584 
585  $destination_image = imagecreatetruecolor($resize_dimensions['width'], $resize_dimensions['height']);
586 
587  imagecopyresampled(
588    $destination_image,
589    $source_image,
590    0,
591    0,
592    0,
593    0,
594    $resize_dimensions['width'],
595    $resize_dimensions['height'],
596    $source_width,
597    $source_height
598    );
599
600  // rotation occurs only on resized photo to avoid useless memory use
601  if (isset($rotation))
602  {
603    $destination_image = imagerotate($destination_image, $rotation, 0);
604  }
605 
606  $extension = strtolower(get_extension($destination_filepath));
607  if ($extension == 'png')
608  {
609    imagepng($destination_image, $destination_filepath);
610  }
611  elseif ($extension == 'gif')
612  {
613    imagegif($destination_image, $destination_filepath);
614  }
615  else
616  {
617    imagejpeg($destination_image, $destination_filepath, $quality);
618  }
619  // freeing memory ressources
620  imagedestroy($source_image);
621  imagedestroy($destination_image);
622
623  // everything should be OK if we are here!
624  return true;
625}
626
627function pwg_image_resize_im($source_filepath, $destination_filepath, $max_width, $max_height, $quality, $strip_metadata=false)
628{
629  // extension of the picture filename
630  $extension = strtolower(get_extension($source_filepath));
631  if (!in_array($extension, array('jpg', 'jpeg', 'png')))
632  {
633    die('[Imagick] unsupported file extension');
634  }
635
636  $image = new Imagick($source_filepath);
637
638  $rotation = get_rotation_angle($source_filepath);
639 
640  // width/height
641  $source_width  = $image->getImageWidth();
642  $source_height = $image->getImageHeight();
643 
644  $resize_dimensions = get_resize_dimensions($source_width, $source_height, $max_width, $max_height, $rotation);
645
646  // testing on height is useless in theory: if width is unchanged, there
647  // should be no resize, because width/height ratio is not modified.
648  if ($resize_dimensions['width'] == $source_width and $resize_dimensions['height'] == $source_height)
649  {
650    // the image doesn't need any resize! We just copy it to the destination
651    copy($source_filepath, $destination_filepath);
652    return true;
653  }
654
655  $image->setImageCompressionQuality($quality);
656  $image->setInterlaceScheme(Imagick::INTERLACE_LINE);
657 
658  if ($strip_metadata)
659  {
660    // we save a few kilobytes. For example a thumbnail with metadata
661    // weights 25KB, without metadata 7KB.
662    $image->stripImage();
663  }
664 
665  $image->resizeImage($resize_dimensions['width'], $resize_dimensions['height'], Imagick::FILTER_LANCZOS, 0.9);
666
667  if (isset($rotation))
668  {
669    $image->rotateImage(new ImagickPixel(), -$rotation);
670    $image->setImageOrientation(Imagick::ORIENTATION_TOPLEFT);
671  }
672
673  $image->writeImage($destination_filepath);
674  $image->destroy();
675
676  // everything should be OK if we are here!
677  return true;
678}
679
680function get_rotation_angle($source_filepath)
681{
682  global $conf;
683
684  if (!$conf['upload_form_automatic_rotation'])
685  {
686    return null;
687  }
688
689  list($width, $height, $type) = getimagesize($source_filepath);
690  if (IMAGETYPE_JPEG != $type)
691  {
692    return null;
693  }
694 
695  if (!function_exists('exif_read_data'))
696  {
697    return null;
698  }
699
700  $rotation = null;
701 
702  $exif = exif_read_data($source_filepath);
703 
704  if (isset($exif['Orientation']) and preg_match('/^\s*(\d)/', $exif['Orientation'], $matches))
705  {
706    $orientation = $matches[1];
707    if (in_array($orientation, array(3, 4)))
708    {
709      $rotation = 180;
710    }
711    elseif (in_array($orientation, array(5, 6)))
712    {
713      $rotation = 270;
714    }
715    elseif (in_array($orientation, array(7, 8)))
716    {
717      $rotation = 90;
718    }
719  }
720
721  return $rotation;
722}
723
724function pwg_image_infos($path)
725{
726  list($width, $height) = getimagesize($path);
727  $filesize = floor(filesize($path)/1024);
728 
729  return array(
730    'width'  => $width,
731    'height' => $height,
732    'filesize' => $filesize,
733    );
734}
735
736function is_valid_image_extension($extension)
737{
738  return in_array(strtolower($extension), array('jpg', 'jpeg', 'png', 'gif'));
739}
740
741function file_upload_error_message($error_code)
742{
743  switch ($error_code) {
744    case UPLOAD_ERR_INI_SIZE:
745      return sprintf(
746        l10n('The uploaded file exceeds the upload_max_filesize directive in php.ini: %sB'),
747        get_ini_size('upload_max_filesize', false)
748        );
749    case UPLOAD_ERR_FORM_SIZE:
750      return l10n('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form');
751    case UPLOAD_ERR_PARTIAL:
752      return l10n('The uploaded file was only partially uploaded');
753    case UPLOAD_ERR_NO_FILE:
754      return l10n('No file was uploaded');
755    case UPLOAD_ERR_NO_TMP_DIR:
756      return l10n('Missing a temporary folder');
757    case UPLOAD_ERR_CANT_WRITE:
758      return l10n('Failed to write file to disk');
759    case UPLOAD_ERR_EXTENSION:
760      return l10n('File upload stopped by extension');
761    default:
762      return l10n('Unknown upload error');
763  }
764}
765
766function get_ini_size($ini_key, $in_bytes=true)
767{
768  $size = ini_get($ini_key);
769
770  if ($in_bytes)
771  {
772    $size = convert_shortand_notation_to_bytes($size);
773  }
774 
775  return $size;
776}
777
778function convert_shortand_notation_to_bytes($value)
779{
780  $suffix = substr($value, -1);
781  $multiply_by = null;
782 
783  if ('K' == $suffix)
784  {
785    $multiply_by = 1024;
786  }
787  else if ('M' == $suffix)
788  {
789    $multiply_by = 1024*1024;
790  }
791  else if ('G' == $suffix)
792  {
793    $multiply_by = 1024*1024*1024;
794  }
795 
796  if (isset($multiply_by))
797  {
798    $value = substr($value, 0, -1);
799    $value*= $multiply_by;
800  }
801
802  return $value;
803}
804
805function add_upload_error($upload_id, $error_message)
806{
807  if (!isset($_SESSION['uploads_error']))
808  {
809    $_SESSION['uploads_error'] = array();
810  }
811  if (!isset($_SESSION['uploads_error'][$upload_id]))
812  {
813    $_SESSION['uploads_error'][$upload_id] = array();
814  }
815
816  array_push($_SESSION['uploads_error'][$upload_id], $error_message);
817}
818
819function is_imagick()
820{
821  if (class_exists('Imagick'))
822  {
823    return true;
824  }
825
826  return false;
827}
828
829function ready_for_upload_message()
830{
831  global $conf;
832
833  $relative_dir = preg_replace('#^'.PHPWG_ROOT_PATH.'#', '', $conf['upload_dir']);
834
835  if (!is_dir($conf['upload_dir']))
836  {
837    if (!is_writable(dirname($conf['upload_dir'])))
838    {
839      return sprintf(
840        l10n('Create the "%s" directory at the root of your Piwigo installation'),
841        $relative_dir
842        );
843    }
844  }
845  else
846  {
847    if (!is_writable($conf['upload_dir']))
848    {
849      @chmod($conf['upload_dir'], 0777);
850     
851      if (!is_writable($conf['upload_dir']))
852      {
853        return sprintf(
854          l10n('Give write access (chmod 777) to "%s" directory at the root of your Piwigo installation'),
855          $relative_dir
856          );
857      }
858    }
859  }
860
861  return null;
862}
863
864function file_path_for_type($file_path, $type='thumb')
865{
866  // resolve the $file_path depending on the $type
867  if ('thumb' == $type) {
868    $file_path = get_thumbnail_location(
869      array(
870        'path' => $file_path,
871        'tn_ext' => 'jpg',
872        )
873      );
874  }
875
876  if ('high' == $type) {
877    @include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
878    $file_path = get_high_location(
879      array(
880        'path' => $file_path,
881        'has_high' => 'true'
882        )
883      );
884  }
885
886  return $file_path;
887}
888?>
Note: See TracBrowser for help on using the repository browser.