1
0
Fork 0

png support: update database.sql, fix some typos, fix tinymce image browser

This commit is contained in:
Fabio Comuni 2012-06-07 20:17:31 +02:00
parent 7cc8c369cb
commit 2438c6e45d
6 changed files with 35 additions and 20 deletions

View file

@ -745,6 +745,7 @@ CREATE TABLE IF NOT EXISTS `photo` (
`desc` text NOT NULL, `desc` text NOT NULL,
`album` char(255) NOT NULL, `album` char(255) NOT NULL,
`filename` char(255) NOT NULL, `filename` char(255) NOT NULL,
`type` CHAR(128) NOT NULL DEFAULT 'image/jpeg',
`height` smallint(6) NOT NULL, `height` smallint(6) NOT NULL,
`width` smallint(6) NOT NULL, `width` smallint(6) NOT NULL,
`data` mediumblob NOT NULL, `data` mediumblob NOT NULL,

View file

@ -105,9 +105,9 @@ class Photo {
$dest = imagecreatetruecolor( $dest_width, $dest_height ); $dest = imagecreatetruecolor( $dest_width, $dest_height );
imagealphablending($dest->image, false); imagealphablending($dest, false);
imagesavealpha($dest, true); imagesavealpha($dest, true);
if ($this->type=='image/png') imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127));; // fill with alpha if ($this->type=='image/png') imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dest_width, $dest_height, $width, $height); imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dest_width, $dest_height, $width, $height);
if($this->image) if($this->image)
imagedestroy($this->image); imagedestroy($this->image);
@ -164,9 +164,9 @@ class Photo {
$dest = imagecreatetruecolor( $dest_width, $dest_height ); $dest = imagecreatetruecolor( $dest_width, $dest_height );
imagealphablending($dest->image, false); imagealphablending($dest, false);
imagesavealpha($dest, true); imagesavealpha($dest, true);
if ($this->type=='image/png') imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127));; // fill with alpha if ($this->type=='image/png') imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dest_width, $dest_height, $width, $height); imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dest_width, $dest_height, $width, $height);
if($this->image) if($this->image)
imagedestroy($this->image); imagedestroy($this->image);
@ -181,9 +181,9 @@ class Photo {
public function scaleImageSquare($dim) { public function scaleImageSquare($dim) {
$dest = imagecreatetruecolor( $dim, $dim ); $dest = imagecreatetruecolor( $dim, $dim );
imagealphablending($dest->image, false); imagealphablending($dest, false);
imagesavealpha($dest, true); imagesavealpha($dest, true);
if ($this->type=='image/png') imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127));; // fill with alpha if ($this->type=='image/png') imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dim, $dim, $this->width, $this->height); imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dim, $dim, $this->width, $this->height);
if($this->image) if($this->image)
imagedestroy($this->image); imagedestroy($this->image);
@ -195,9 +195,9 @@ class Photo {
public function cropImage($max,$x,$y,$w,$h) { public function cropImage($max,$x,$y,$w,$h) {
$dest = imagecreatetruecolor( $max, $max ); $dest = imagecreatetruecolor( $max, $max );
imagealphablending($dest->image, false); imagealphablending($dest, false);
imagesavealpha($dest, true); imagesavealpha($dest, true);
if ($this->type=='image/png') imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127));; // fill with alpha if ($this->type=='image/png') imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
imagecopyresampled($dest, $this->image, 0, 0, $x, $y, $max, $max, $w, $h); imagecopyresampled($dest, $this->image, 0, 0, $x, $y, $max, $max, $w, $h);
if($this->image) if($this->image)
imagedestroy($this->image); imagedestroy($this->image);
@ -295,6 +295,7 @@ class Photo {
* @arg $fromcurl boolean Check Content-Type header from curl request * @arg $fromcurl boolean Check Content-Type header from curl request
*/ */
function guess_image_type($filename, $fromcurl=false) { function guess_image_type($filename, $fromcurl=false) {
logger('Photo: guess_image_type: '.$filename . ($fromcurl?' from curl headers':''), LOGGER_DEBUG);
$type = null; $type = null;
if ($fromcurl) { if ($fromcurl) {
$a = get_app(); $a = get_app();
@ -310,12 +311,13 @@ function guess_image_type($filename, $fromcurl=false) {
if (is_null($type)){ if (is_null($type)){
$ext = pathinfo($filename, PATHINFO_EXTENSION); $ext = pathinfo($filename, PATHINFO_EXTENSION);
$types = Photo::supportedTypes(); $types = Photo::supportedTypes();
foreach ($types as $m=>$e){
if ($ext==$e) return $m;
}
$type = "image/jpeg"; $type = "image/jpeg";
} foreach ($types as $m=>$e){
if ($ext==$e) $type = $m;
}
}
logger('Photo: guess_image_type: type='.$type, LOGGER_DEBUG);
return $type; return $type;
} }

View file

@ -5,6 +5,8 @@
* @author Fabio Comuni <fabrixxm@kirgroup.com> * @author Fabio Comuni <fabrixxm@kirgroup.com>
*/ */
require_once('include/Photo.php');
/** /**
* @param App $a * @param App $a
*/ */
@ -43,14 +45,22 @@ function fbrowser_content($a){
$path[]=array($a->get_baseurl()."/fbrowser/image/".$a->argv[2]."/", $album); $path[]=array($a->get_baseurl()."/fbrowser/image/".$a->argv[2]."/", $album);
} }
$r = q("SELECT `resource-id`, `id`, `filename`, min(`scale`) AS `hiq`,max(`scale`) AS `loq`, `desc` $r = q("SELECT `resource-id`, `id`, `filename`, type, min(`scale`) AS `hiq`,max(`scale`) AS `loq`, `desc`
FROM `photo` WHERE `uid` = %d $sql_extra FROM `photo` WHERE `uid` = %d $sql_extra
GROUP BY `resource-id` $sql_extra2", GROUP BY `resource-id` $sql_extra2",
intval(local_user()) intval(local_user())
); );
function files1($rr){
function files1($rr){ global $a; return array( $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['hiq'] . '.jpg', template_escape($rr['filename']), $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['loq'] . '.jpg'); } global $a;
$types = Photo::supportedTypes();
$ext = $types[$rr['type']];
return array(
$a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['hiq'] . '.' .$ext,
template_escape($rr['filename']),
$a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['loq'] . '.'. $ext
);
}
$files = array_map("files1", $r); $files = array_map("files1", $r);
$tpl = get_markup_template("filebrowser.tpl"); $tpl = get_markup_template("filebrowser.tpl");

View file

@ -682,9 +682,9 @@ function photos_post(&$a) {
$filesize = intval($_FILES['userfile']['size']); $filesize = intval($_FILES['userfile']['size']);
$type = $_FILES['userfile']['type']; $type = $_FILES['userfile']['type'];
} }
if ($type=="") $type=guess_image_type($filename);
logger('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', LOGGER_DEBUG);
logger('photos: upload: received file: ' . $filename . ' as ' . $src . ' '. $type . ' ' . $filesize . ' bytes', LOGGER_DEBUG);
$maximagesize = get_config('system','maximagesize'); $maximagesize = get_config('system','maximagesize');

View file

@ -109,6 +109,7 @@ function profile_photo_post(&$a) {
$filename = basename($_FILES['userfile']['name']); $filename = basename($_FILES['userfile']['name']);
$filesize = intval($_FILES['userfile']['size']); $filesize = intval($_FILES['userfile']['size']);
$filetype = $_FILES['userfile']['type']; $filetype = $_FILES['userfile']['type'];
if ($filetype=="") $filetype=guess_image_type($filename);
$maximagesize = get_config('system','maximagesize'); $maximagesize = get_config('system','maximagesize');

View file

@ -70,6 +70,7 @@ function wall_upload_post(&$a) {
$filetype = $_FILES['media']['type']; $filetype = $_FILES['media']['type'];
} }
if ($filetype=="") $filetype=guess_image_type($filename);
$maximagesize = get_config('system','maximagesize'); $maximagesize = get_config('system','maximagesize');
if(($maximagesize) && ($filesize > $maximagesize)) { if(($maximagesize) && ($filesize > $maximagesize)) {