48 $xml =
"\n<ImageMap>";
51 $xml .=
"</ImageMap>";
56 function import($doc,
$tx)
113 trace(
"renderThumbnail:: image = {$image->image_id} and gallery = {$gallery->gallery_id}", 3);
124 $nameParts = explode(
".",
$image->image_file);
125 $ext =
".".strtolower($nameParts[count($nameParts) - 1]);
127 $imageFile =
$gallery->getGalleryDirectory() . DIRECTORY_SEPARATOR .
$image->image_file;
128 $cacheDir =
$gallery->getGalleryDirectory() . DIRECTORY_SEPARATOR .
"thumbnail-cache";
129 $cacheFile = $cacheDir . DIRECTORY_SEPARATOR .
$image->image_id .
"_" . $suffix . $ext;
130 trace(
"renderThumbnail:: imageFile {$imageFile} and cacheDir {$cacheDir} and cacheFile {$cacheFile}", 3);
132 if (!file_exists($cacheFile) || (filemtime($cacheFile) < filemtime($imageFile)))
137 $src = imagecreatefromjpeg($imageFile);
141 $src = imagecreatefromjpeg($imageFile);
145 $src = imagecreatefrompng($imageFile);
149 $src = imagecreatefromgif($imageFile);
154 $fullWidth = imagesx(
$src);
155 $fullHeight = imagesy(
$src);
159 if ($fullWidth > $fullHeight)
162 $newHeight = intval(($fullHeight *
$size) / $fullWidth);
167 $newWidth = intval(($fullWidth *
$size) / $fullHeight);
174 $newHeight = intval(($fullHeight *
$width) / $fullWidth);
179 $newWidth = intval(($fullWidth *
$height) / $fullHeight);
183 $newWidth = $fullWidth;
184 $newHeight = $fullHeight;
187 $dst = imagecreatetruecolor($newWidth, $newHeight);
188 imagealphablending($dst,
false);
189 imagesavealpha($dst,
true);
191 $trans = imagecolorallocatealpha($dst, 255, 255, 255, 127);
192 $white = imagecolorallocate($dst, 255, 255, 255);
194 imagecolortransparent($dst, $trans);
196 imagefilledrectangle($dst, 0, 0, $newWidth, $newHeight, $white);
197 imagefilledrectangle($dst, 0, 0, $newWidth, $newHeight, $trans);
199 imagecopyresampled($dst,
$src, 0, 0, 0, 0, $newWidth, $newHeight, $fullWidth, $fullHeight);
201 if (!file_exists($cacheDir))
203 trace(
"renderThumbnail:: creating cachedir", 3);
207 if (file_exists($cacheFile))
210 trace(
"renderThumbnail:: unlinking cachefile", 3);
218 imagejpeg($dst, $cacheFile, 85);
223 imagejpeg($dst, $cacheFile, 85);
228 imagepng($dst, $cacheFile);
232 imagegif($dst, $cacheFile);
257 $imageFile =
$gallery->getGalleryDirectory() . DIRECTORY_SEPARATOR .
$image->image_file;
275 trace(
"resizeAndCropToFit:: image = {$image->image_id} and gallery = {$gallery->gallery_id}", 3);
284 $suffix =
"cropTo_{$width}x{$height}";
286 $nameParts = explode(
".",
$image->image_file);
287 $ext =
".".strtolower($nameParts[count($nameParts) - 1]);
289 $imageFile =
$gallery->getGalleryDirectory() . DIRECTORY_SEPARATOR .
$image->image_file;
290 $cacheDir =
$gallery->getGalleryDirectory() . DIRECTORY_SEPARATOR .
"thumbnail-cache";
291 $cacheFile = $cacheDir . DIRECTORY_SEPARATOR .
$image->image_id .
"_" . $suffix .
"." .
$gallery->getThumbnailFormat();
292 trace(
"renderThumbnail:: imageFile {$imageFile} and cacheDir {$cacheDir} and cacheFile {$cacheFile}", 3);
294 if (!file_exists($cacheFile) || (filemtime($cacheFile) < filemtime($imageFile)))
299 $src = imagecreatefromjpeg($imageFile);
303 $src = imagecreatefromjpeg($imageFile);
307 $src = imagecreatefrompng($imageFile);
311 $src = imagecreatefromgif($imageFile);
316 $fullWidth = imagesx(
$src);
317 $fullHeight = imagesy(
$src);
321 $srcHeight = $fullWidth / $aspect;
322 $offset = ($fullHeight - $srcHeight) / 2;
325 imagealphablending($dst,
false);
326 imagesavealpha($dst,
true);
328 $trans = imagecolorallocatealpha($dst, 255, 255, 255, 127);
329 imagecolortransparent($dst, $trans);
335 if (!file_exists($cacheDir))
337 trace(
"renderThumbnail:: creating cachedir", 3);
341 if (file_exists($cacheFile))
344 trace(
"renderThumbnail:: unlinking cachefile", 3);
348 switch(
$gallery->getThumbnailFormat())
352 imagejpeg($dst, $cacheFile, 85);
357 imagepng($dst, $cacheFile);
382 trace(
"resizeAndCropToCover:: image = {$image->image_id} and gallery = {$gallery->gallery_id}", 3);
398 $suffix =
"cover_{$width}x{$height}";
400 $nameParts = explode(
".",
$image->image_file);
401 $ext =
".".strtolower($nameParts[count($nameParts) - 1]);
403 $imageFile =
$gallery->getGalleryDirectory() . DIRECTORY_SEPARATOR .
$image->image_file;
404 $cacheDir =
$gallery->getGalleryDirectory() . DIRECTORY_SEPARATOR .
"thumbnail-cache";
405 $cacheFile = $cacheDir . DIRECTORY_SEPARATOR .
$image->image_id .
"_" . $suffix .
"." .
$gallery->getThumbnailFormat();
406 trace(
"renderThumbnail:: imageFile {$imageFile} and cacheDir {$cacheDir} and cacheFile {$cacheFile}", 3);
408 if (!file_exists($cacheFile) || (filemtime($cacheFile) < filemtime($imageFile)))
413 $src = imagecreatefromjpeg($imageFile);
417 $src = imagecreatefromjpeg($imageFile);
421 $src = imagecreatefrompng($imageFile);
425 $src = imagecreatefromgif($imageFile);
430 $fullWidth = imagesx(
$src);
431 $fullHeight = imagesy(
$src);
436 if ($fullWidth > $fullHeight)
439 $newWidth = intval(($fullWidth *
$size) / $fullHeight);
440 $offsetX = (
$size - $newWidth) / 2;
446 $newHeight = intval(($fullHeight *
$size) / $fullWidth);
447 $offsetY = (
$size - $newHeight) / 2;
453 imagealphablending($dst,
false);
454 imagesavealpha($dst,
true);
456 $trans = imagecolorallocatealpha($dst, 255, 255, 255, 127);
457 imagecolortransparent($dst, $trans);
461 imagecopyresampled($dst,
$src, $offsetX, $offsetY, 0, 0, $newWidth, $newHeight, $fullWidth, $fullHeight);
463 if (!file_exists($cacheDir))
465 trace(
"renderThumbnail:: creating cachedir", 3);
469 if (file_exists($cacheFile))
472 trace(
"renderThumbnail:: unlinking cachefile", 3);
476 switch(
$gallery->getThumbnailFormat())
480 imagejpeg($dst, $cacheFile, 85);
485 imagepng($dst, $cacheFile);
499 $path = Cache::get(
"image_{$mode}_{$image_id}_{$size}");
506 Cache::put(
"image_{$mode}_{$image_id}_{$size}",
$path);
529 trace(
"iconize:: image = {$image->image_id} and gallery = {$gallery->gallery_id}", 3);
538 $suffix =
"icon_$size";
540 $nameParts = explode(
".",
$image->image_file);
541 $ext =
".".strtolower($nameParts[count($nameParts) - 1]);
543 $imageFile =
$gallery->getGalleryDirectory() . DIRECTORY_SEPARATOR .
$image->image_file;
544 $cacheDir =
$gallery->getGalleryDirectory() . DIRECTORY_SEPARATOR .
"thumbnail-cache";
545 $cacheFile = $cacheDir . DIRECTORY_SEPARATOR .
$image->image_id .
"_" . $suffix .
"." .
$gallery->getThumbnailFormat();
546 trace(
"renderThumbnail:: imageFile {$imageFile} and cacheDir {$cacheDir} and cacheFile {$cacheFile}", 3);
548 if (!file_exists($cacheFile) || (filemtime($cacheFile) < filemtime($imageFile)))
553 $src = imagecreatefromjpeg($imageFile);
557 $src = imagecreatefromjpeg($imageFile);
561 $src = imagecreatefrompng($imageFile);
565 $src = imagecreatefromgif($imageFile);
570 $fullWidth = imagesx(
$src);
571 $fullHeight = imagesy(
$src);
575 if ($fullWidth > $fullHeight)
578 $newHeight = intval(($fullHeight *
$size) / $fullWidth);
583 $newWidth = intval(($fullWidth *
$size) / $fullHeight);
590 $newHeight = intval(($fullHeight *
$width) / $fullWidth);
595 $newWidth = intval(($fullWidth *
$height) / $fullHeight);
599 $newWidth = $fullWidth;
600 $newHeight = $fullHeight;
603 $offsetX = (
$size - $newWidth) / 2;
604 $offsetY = (
$size - $newHeight) / 2;
609 $trans = imagecolorallocatealpha($dst, 255, 255, 255, 127);
610 $white = imagecolorallocate($dst, 255, 255, 255);
612 imagecolortransparent($dst, $trans);
614 imagefilledrectangle($dst, 0, 0,
$size,
$size, $white);
615 imagefilledrectangle($dst, 0, 0,
$size,
$size, $trans);
618 imagecopyresampled($dst,
$src, $offsetX, $offsetY, 0, 0, $newWidth, $newHeight, $fullWidth, $fullHeight);
620 if (!file_exists($cacheDir))
622 trace(
"iconize:: creating cachedir", 3);
626 if (file_exists($cacheFile))
629 trace(
"iconize:: unlinking cachefile", 3);
633 trace(
"Writing $cacheFile", 3);
635 switch(
$gallery->getThumbnailFormat())
639 imagejpeg($dst, $cacheFile, 85);
644 imagepng($dst, $cacheFile);
668 trace(
"Cropping image $id, starting at ($x, $y) dimensions ($w, $h)", 3);
679 $imageFile =
$gallery->getGalleryDirectory() . DIRECTORY_SEPARATOR .
$image->image_file;
681 $nameParts = explode(
".",
$image->image_file);
682 $ext =
".".strtolower($nameParts[1]);
684 if (!file_exists($cacheFile) || (filemtime($cacheFile) < filemtime($imageFile)))
690 $src = imagecreatefromjpeg($imageFile);
694 $src = imagecreatefrompng($imageFile);
698 $src = imagecreatefromgif($imageFile);
703 $dst = ImageCreateTrueColor( $w, $h );
705 imagecopy($dst,
$src, 0, 0, $x, $y, $w, $h);
711 imagejpeg($dst, $imageFile, 85);
715 $src = imagegif($imageFile);
720 imagepng($dst, $imageFile);
736 $handler = $iconize ?
"iconize" :
"thumbnail";
737 return "/action/image/{$handler}?image_id=$image_id&size=$size";
742 return "/action/image/show?image_id=$image_id";
762 $imageFile =
$gallery->getGalleryDirectory() . DIRECTORY_SEPARATOR .
$image->image_file;
764 $img = imageCreateFromString(file_get_contents($imageFile));
808 $_GET[
"gallery_id"] =
$gallery->gallery_id;
814 if (!checkRole(
$page->role))
820 echo $pageView->drawView();
824 catch(DataNotFoundException $e)
854 trace(
"Cannot find $filename", 2);
859 $png_header = array(0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A);
865 $header = fread(
$f, 8);
869 $chars = preg_split(
'//', $header, -1, PREG_SPLIT_NO_EMPTY);
872 $chars = array_map(
'ord', $chars);
875 return (count(array_diff($png_header, $chars)) === 0);
891 trace(
"Cannot find $filename", 2);
896 $png_header = array(0xFF, 0xD8, 0xFF);
902 $header = fread(
$f, 3);
906 $chars = preg_split(
'//', $header, -1, PREG_SPLIT_NO_EMPTY);
909 $chars = array_map(
'ord', $chars);
912 return (count(array_diff($png_header, $chars)) === 0);
925 trace(
"imageUploadHandler() called for $field", 3);
929 trace(
"No upload record for $field", 3);
932 if ($_FILES[
$field][
"name"]==
"")
934 trace(
"Upload name is empty", 3);
941 if (!file_exists(
$dir))
948 trace(
"Upload Base: {$dir}", 3);
953 $ext =
".".strtolower($nameParts[1]);
958 $filename = strtolower($nameParts[0]) . $ext;
963 trace(
"Image format: $ext", 3);
965 if ($ext !=
".jpg" && $ext !=
".png" && $ext !=
".svg")
977 trace (
"Uploading file to $target", 3);
987 if (
$gallery->fix_orientation && $ext ==
".jpg")
994 $image->set(
"image_type",
"image/png");
1016 trace(
"Checking Photo Orientation", 3);
1018 $exif = read_exif_data($photo);
1020 switch($exif[
'Orientation'])
1036 trace(
"No rotation required", 3);
1040 $source = imagecreatefromjpeg($photo);
1041 $rotated = imagerotate(
$source, $angle, 0);
1043 trace(
"Rotating $angle degrees", 3);
1045 $photo = preg_replace(
"/\.jpg\$/",
".png", $photo);
1047 trace(
"Saving to $photo");
1049 imagepng($rotated, $photo);
1067 $process->setProgress(
"Running",
"Scanning files", 0);
1070 $files =
$gallery->Images(
"ORDER BY image_file");
1072 $galleryFileName =
$gallery->identifier ?
$gallery->format(
"{identifier}.zip") :
$gallery->format(
"gallery_{gallery_id}.zip");
1073 $galleryDir =
$gallery->getGalleryDirectory();
1074 $galleryZipFile =
$config[
'uploadbase'] . DIRECTORY_SEPARATOR . $galleryFileName;
1075 if (file_exists($galleryZipFile))
1077 unlink($galleryZipFile);
1081 $zip =
new ZipArchive();
1084 if ($zip->open($galleryZipFile, ZIPARCHIVE::CREATE) !== TRUE)
1088 $process->setProgress(
"Error",
"Could not create ZIP archive");
1093 $max = count($files);
1096 foreach($files as
$file)
1098 $fullPath = $galleryDir . DIRECTORY_SEPARATOR .
$file->image_file;
1099 $zip->addFile($fullPath,
$file->image_file);
1103 $process->setProgress(
"Running",
"Added $c of $max ".pluralize(
"file",
$max), number_format(100 *
$c /
$max, 0));
1111 $process->setProgress(
"Completed",
"Zip archive created", 100);
1118 "Definition" =>
"image_gallery_form",
1119 "Thumbnails" =>
"images",
1120 "Detailed List" =>
"image_list"
1123 $qs = ($key) ?
"gallery_id=$key" :
"";
1124 return new TabBar(
"tabs",
$tabs,
$qs);
1129 $styles .=
"<link href=\"/fakoli/css/tabs.css\" rel=\"stylesheet\"/>\n";
1136 trace(
"ImageManager::setDefaults", 3);
1139 Settings::setDefaultValue(
"image",
"thumbnail_format",
"png",
"String",
"Use PNG for high quality thumbnails (default) or JPG for fast, low bandwidth thumbnails. JPG files will have lower image quality and do not support transparency",
"",
"png\njpg");
1140 Settings::setDefaultValue(
"image",
"cache_file_paths",
false,
"Boolean",
"Cache image file paths in memory for increased performance");
1141 Settings::setDefaultValue(
"image",
"retina_mode",
false,
"Boolean",
"Double the resolution of images in image grids to provide better quality on high-DPI displays");
1153 $mgr->upgrade($version);
1168 trace(
"Component image is deleting objects dependent on user_id {$user_id}", 3);
1171 $gallery->delete(
"WHERE owner_id={$user_id}");
1192 $images = $this->gallery->Images();
1195 $this->indexedImages = reindexList(
$images,
"image_file");
1199 $this->indexedImages = array();
1207 $base = sanitizePath($this->gallery->getGalleryDirectory());
1209 $files = scandir(
$base);
1210 foreach($files as
$file)
1214 if ($this->indexedImages[
$file])
continue;
1220 $image->published =
true;
1221 $image->gallery_id = $this->gallery->gallery_id;
static findByIdentifier($identifier, $constraint="")
ComponentPageView generates the page content for a component page, substituting page fields,...
FakoliException is the base exception class for all Fakoli errors.
static sendFile($resource)
Sends the contents of the specified file to the client.
static assertRole($role, $redirect="", $message="")
Assert that the user has one of the specified roles.
The ImageManager class provides basic Image manipulation functions that are useful when working with ...
renderImage($image_id)
Renders the specified image at its natural size.
renderThumbnail($image_id, $size=0, $width=0, $height=0)
Renders the Image specified by the image_id at the specified size.
static isJPG($filename)
Test the contents of the specified file, returning true if a JPEG header signature is found.
static zipGallery($gallery_id, $process=null)
Generate a ZIP archive of all the images in the specified gallery.
getSize($image_id, &$width, &$height)
Determines the size of the specified image.
thumbnailLink($image_id, $size, $iconize=false)
Returns the URI that can be used to access the specified image at the given size.
static displayImageGallery($identifier, &$continue)
Event handler to display an image gallery from the specified identifier.
static registerSerializationHandler()
iconize($image_id, $size)
crop($id, $x, $y, $w, $h)
Crop the image to the specified dimensions.
static imageGalleryTabs($key)
resizeAndCropToCover($image_id, $width, $height)
static imageUploadHandler($field, $image)
Upload the image file specified in the given field.
ImageManager()
Creates a new ImageManager.
static isPNG($filename)
Test the contents of the specified file, returning true if a PNG header signature is found.
getScaledSize($image_id, $size, &$width, &$height)
Calculates the width and height of an image after it is scaled to the specified size along its major ...
static upgradeComponent($version)
static registerTaxonomyClasses($classes)
getCachedFilePath($image_id, $mode, $size)
static deleteUser($user)
Respond to fired event DeleteUser.
static enumerateItems($items)
Enumerate the Image Gallery objects.
cacheFilePath($image_id, $mode, $size, $path)
static fixOrientation($photo)
Rotates the image to match the correct orientation when orientation information is included in the im...
resizeAndCropToFit($image_id, $width, $height)
ImageSerializationHandler()
static storeRedirectPage()
Store the page from which a user has been redirected when prompted to login or create an account.
static serialize($class, $constraint="")
Serializes the specified DataItems to XML.
registerHandler($component, $title, $handler)
Registers a serialization handler for a component.
static unserialize($class, $doc, $tx, $save=true)
Instantiates DataItems from the supplied XML document and stores them in the database.
static getValue($component, $name)
Retrieve the value of the specified Setting.
static setDefaultValue($component, $name, $value, $field_type="String", $annotation="", $category="", $options="", $weight=0)
Sets the default value of the given component setting.
if(!checkRole("admin")) $c
if(!Settings::getValue("debug", "enable_trace_file_downloads")) $filename