aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorCash Costello <cash.costello@gmail.com>2010-10-24 01:53:21 +0000
committerCash Costello <cash.costello@gmail.com>2010-10-24 01:53:21 +0000
commit5161b1c8fdc8ff69005f864a89127fc18db6d4ed (patch)
treea8ee6e335ebfafa45ecfba63e27dbc856d6db12f /lib
parentc1913c4e6873aae185033d8cb82df1c6cee11480 (diff)
downloadelgg-5161b1c8fdc8ff69005f864a89127fc18db6d4ed.tar.gz
elgg-5161b1c8fdc8ff69005f864a89127fc18db6d4ed.tar.bz2
started cleaning up the upload action
Diffstat (limited to 'lib')
-rw-r--r--lib/image.php66
-rw-r--r--lib/upload.php38
2 files changed, 104 insertions, 0 deletions
diff --git a/lib/image.php b/lib/image.php
index 7c7ef2d90..51b31f6d7 100644
--- a/lib/image.php
+++ b/lib/image.php
@@ -39,6 +39,72 @@ class TidypicsImage extends ElggFile {
}
/**
+ * Set the internal filenames
+ *
+ * @warning container needs to be set first
+ */
+ public function setOriginalFilename($originalName) {
+ $prefix = "image/" . $this->container_guid . "/";
+ $filestorename = strtolower(time() . $originalName);
+ $this->setFilename($prefix . $filestorename);
+ $this->originalfilename = $originalName;
+ }
+
+ /**
+ * Save the uploaded image
+ *
+ * @warning filename needs to be set first
+ *
+ * @param string $image
+ */
+ public function saveImageFile($image) {
+ $this->open("write");
+ $this->write($image);
+ $this->close();
+ }
+
+ /**
+ * Save the image thumbnails
+ *
+ * @warning container guid and filename must be set
+ *
+ * @param string $imageLib
+ */
+ public function saveThumbnails($imageLib) {
+ include_once dirname(__FILE__) . "/resize.php";
+
+ $prefix = "image/" . $this->container_guid . "/";
+ $filename = $this->getFilename();
+ $filename = substr($filename, strrpos($filename, '/') + 1);
+
+ if ($imageLib == 'ImageMagick') {
+ // ImageMagick command line
+ if (tp_create_im_cmdline_thumbnails($this, $prefix, $filename) != true) {
+ trigger_error('Tidypics warning: failed to create thumbnails - ImageMagick command line', E_USER_WARNING);
+ }
+ } else if ($imageLib == 'ImageMagickPHP') {
+ // imagick php extension
+ if (tp_create_imagick_thumbnails($this, $prefix, $filename) != true) {
+ trigger_error('Tidypics warning: failed to create thumbnails - ImageMagick PHP', E_USER_WARNING);
+ }
+ } else {
+ if (tp_create_gd_thumbnails($this, $prefix, $filename) != true) {
+ trigger_error('Tidypics warning: failed to create thumbnails - GD', E_USER_WARNING);
+ }
+ }
+ }
+
+ /**
+ * Extract EXIF Data from image
+ *
+ * @warning image file must be saved first
+ */
+ public function extractExifData() {
+ include_once dirname(__FILE__) . "/exif.php";
+ td_get_exif($this);
+ }
+
+ /**
* Has the photo been tagged with "in this photo" tags
*
* @return true/false
diff --git a/lib/upload.php b/lib/upload.php
new file mode 100644
index 000000000..a7dd7611d
--- /dev/null
+++ b/lib/upload.php
@@ -0,0 +1,38 @@
+<?php
+/**
+ * Helper library for working with uploads
+ */
+
+function tp_upload_check_format($mime) {
+ $accepted_formats = array(
+ 'image/jpeg',
+ 'image/png',
+ 'image/gif',
+ 'image/pjpeg',
+ 'image/x-png',
+ );
+
+ if (!in_array($mime, $accepted_formats)) {
+ return false;
+ }
+ return true;
+}
+
+function tp_upload_memory_check($image_lib, $num_pixels) {
+ if ($image_lib !== 'GD') {
+ return true;
+ }
+
+ $mem_avail = ini_get('memory_limit');
+ $mem_avail = rtrim($mem_avail, 'M');
+ $mem_avail = $mem_avail * 1024 * 1024;
+ $mem_used = memory_get_usage();
+ $mem_required = ceil(5.35 * $num_pixels);
+
+ $mem_avail = $mem_avail - $mem_used - 2097152; // 2 MB buffer
+ if ($mem_required > $mem_avail) {
+ return false;
+ }
+
+ return true;
+} \ No newline at end of file