Skip to content

Commit

Permalink
merge r6616 from branch 2.1 to trunk
Browse files Browse the repository at this point in the history
bug 1701 fixed: support for PNG file in browser direct upload.

If the picture is a PNG file, then the "web size" picture is also a PNG file
but the thumbnail is always a JPEG file.



git-svn-id: http://piwigo.org/svn/trunk@6617 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
plegall committed Jun 28, 2010
1 parent 7125711 commit c6d981c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
26 changes: 22 additions & 4 deletions admin/include/functions_upload.inc.php
Expand Up @@ -42,7 +42,17 @@ function add_uploaded_file($source_filepath, $original_filename=null, $categorie
$date_string = preg_replace('/[^\d]/', '', $dbnow);
$random_string = substr($md5sum, 0, 8);
$filename_wo_ext = $date_string.'-'.$random_string;
$file_path = $upload_dir.'/'.$filename_wo_ext.'.jpg';
$file_path = $upload_dir.'/'.$filename_wo_ext.'.';

list($width, $height, $type) = getimagesize($source_filepath);
if (IMAGETYPE_PNG == $type)
{
$file_path.= 'png';
}
else
{
$file_path.= 'jpg';
}

prepare_directory($upload_dir);
if (is_uploaded_file($source_filepath))
Expand Down Expand Up @@ -198,11 +208,11 @@ function pwg_image_resize($result, $source_filepath, $destination_filepath, $max
$source_image = null;
if (in_array($extension, array('jpg', 'jpeg')))
{
$source_image = @imagecreatefromjpeg($source_filepath);
$source_image = imagecreatefromjpeg($source_filepath);
}
else if ($extension == 'png')
{
$source_image = @imagecreatefrompng($source_filepath);
$source_image = imagecreatefrompng($source_filepath);
}
else
{
Expand Down Expand Up @@ -252,7 +262,15 @@ function pwg_image_resize($result, $source_filepath, $destination_filepath, $max
$source_height
);

imagejpeg($destination_image, $destination_filepath, $quality);
$extension = strtolower(get_extension($destination_filepath));
if ($extension == 'png')
{
imagepng($destination_image, $destination_filepath);
}
else
{
imagejpeg($destination_image, $destination_filepath, $quality);
}
// freeing memory ressources
imagedestroy($source_image);
imagedestroy($destination_image);
Expand Down
4 changes: 2 additions & 2 deletions admin/themes/default/template/photos_add_direct.tpl
Expand Up @@ -106,8 +106,8 @@ var buttonText = 'Browse';
'displayData' : 'speed',
'buttonText' : buttonText,
'multi' : true,
'fileDesc' : 'Photo files (*.jpg,*.jpeg)',
'fileExt' : '*.jpg;*.JPG;*.jpeg;*.JPEG',
'fileDesc' : 'Photo files (*.jpg,*.jpeg,*.png)',
'fileExt' : '*.jpg;*.JPG;*.jpeg;*.JPEG;*.png;*.PNG',
'onAllComplete' : function(event, data) {
if (data.errors) {
return false;
Expand Down

0 comments on commit c6d981c

Please sign in to comment.