Commit b609d465 authored by Richard Mansfield's avatar Richard Mansfield Committed by Gerrit Code Review
Browse files

Merge changes I838acf82,I4f7f9dde,Id49b75bc,Iaa19508f,I65760638,I602869fa,I8d64b443

* changes:
  Add required db fields for 'resize images on upload' feature.
  Add language and help files for 'resize images on upload' feature.
  Add option to set default user setting for 'resize images on upload'.
  Display 'resize images on upload' option in filebrowser form element.
  Add 'resize images on upload' support to filebrowser pieform element.
  Add dedicated image resizer class.
  Resize Large Images On Upload
parents 8c356355 6e2b9636
......@@ -392,5 +392,14 @@ function xmldb_artefact_file_upgrade($oldversion=0) {
}
}
if ($oldversion < 2012050400) {
if (!get_record('artefact_config', 'plugin', 'file', 'field', 'resizeonuploadenable')) {
insert_record('artefact_config', (object) array('plugin' => 'file', 'field' => 'resizeonuploadenable', 'value' => 0));
insert_record('artefact_config', (object) array('plugin' => 'file', 'field' => 'resizeonuploaduseroption', 'value' => 0));
insert_record('artefact_config', (object) array('plugin' => 'file', 'field' => 'resizeonuploadmaxheight', 'value' => get_config('imagemaxheight')));
insert_record('artefact_config', (object) array('plugin' => 'file', 'field' => 'resizeonuploadmaxwidth', 'value' => get_config('imagemaxwidth')));
}
}
return $status;
}
......@@ -112,6 +112,12 @@ function pieform_element_filebrowser(Pieform $form, $element) {
$config['simpleupload'] = 1;
}
if ($config['resizeonuploaduseroption'] == 1) {
$smarty->assign('resizeonuploadenable', get_config_plugin('artefact', 'file', 'resizeonuploadenable'));
$smarty->assign('resizeonuploadmaxwidth', get_config_plugin('artefact', 'file', 'resizeonuploadmaxwidth'));
$smarty->assign('resizeonuploadmaxheight', get_config_plugin('artefact', 'file', 'resizeonuploadmaxheight'));
}
if ($config['upload']) {
$maxuploadsize = display_size(get_max_upload_size(!$institution && !$group));
$smarty->assign('maxuploadsize', $maxuploadsize);
......@@ -436,6 +442,14 @@ function pieform_element_filebrowser_doupdate(Pieform $form, $element) {
return pieform_element_filebrowser_delete($form, $element, (int) ($keys[0]));
}
$resizeonuploaduserenable = param_variable($prefix . '_resizeonuploaduserenable', null);
if (!empty($resizeonuploaduserenable)) {
$resizeimage = 1;
}
else {
$resizeimage = 0;
}
$update = param_variable($prefix . '_update', null);
if (is_array($update)) {
$edit_title = param_variable($prefix . '_edit_title');
......@@ -548,6 +562,7 @@ function pieform_element_filebrowser_doupdate(Pieform $form, $element) {
'uploadnumber' => param_integer($prefix . '_uploadnumber'),
'uploadfolder' => $element['folder'] ? $element['folder'] : null,
'uploadfoldername' => param_variable($prefix . '_foldername'),
'resizeonuploaduserenable' => $resizeimage,
));
// If it's a non-js upload, automatically select the newly uploaded file.
$result['browse'] = 1;
......@@ -584,6 +599,7 @@ function pieform_element_filebrowser_doupdate(Pieform $form, $element) {
'uploadnumber' => param_integer($prefix . '_uploadnumber') - ($size - $i - 1),
'uploadfolder' => $element['folder'] ? $element['folder'] : null,
'uploadfoldername' => param_variable($prefix . '_foldername'),
'resizeonuploaduserenable' => $resizeimage,
));
// TODO, what to do here...
// If it's a non-js upload, automatically select the newly uploaded file.
......@@ -695,6 +711,9 @@ function pieform_element_filebrowser_upload(Pieform $form, $element, $data) {
$querybase = $element['page'] . (strpos($element['page'], '?') === false ? '?' : '&');
$prefix = $form->get_name() . '_' . $element['name'];
$userfileindex = isset($data['userfileindex']) ? $data['userfileindex'] : null;
$resizeonuploadenable = get_config_plugin('artefact', 'file', 'resizeonuploadenable');
$resizeonuploaduseroption = get_config_plugin('artefact', 'file', 'resizeonuploaduseroption');
$resizeonuploaduserenable = (int) $data['resizeonuploaduserenable'];
$result = array('error' => false, 'uploadnumber' => $uploadnumber);
......@@ -752,8 +771,52 @@ function pieform_element_filebrowser_upload(Pieform $form, $element, $data) {
$originalname = $originalname ? basename($originalname) : get_string('file', 'artefact.file');
$data->title = ArtefactTypeFileBase::get_new_file_title($originalname, $parentfolder, $data->owner, $group, $institution);
// Overwrite image file with resized version if required
$resized = false;
$resizeattempted = false;
// resize specified if (resizing is enabled AND user has enabled resizing) OR (resizing is enabled AND user is not given an option to enable/disable)
if (($resizeonuploadenable && $resizeonuploaduserenable) || ($resizeonuploadenable && !$resizeonuploaduseroption)) {
require_once('file.php');
require_once('imageresizer.php');
$file = $_FILES['userfile'];
if (isset($userfileindex)) {
$tmpname = $file['tmp_name'][$userfileindex];
}
else {
$tmpname = $file['tmp_name'];
}
if (is_image_file($tmpname)) {
$imageinfo = getimagesize($tmpname);
$mimetype = $imageinfo['mime'];
$width = $imageinfo[0];
$height = $imageinfo[1];
$bmptypes = array('image/bmp', 'image/x-bmp', 'image/ms-bmp', 'image/x-ms-bmp');
// resize image if necessary
$resizeonuploadmaxwidth = get_config_plugin('artefact', 'file', 'resizeonuploadmaxwidth');
$resizeonuploadmaxheight = get_config_plugin('artefact', 'file', 'resizeonuploadmaxheight');
// Don't support bmps for now
if (($width > $resizeonuploadmaxwidth || $height > $resizeonuploadmaxheight) && !in_array($mimetype, $bmptypes)) {
$resizeattempted = true;
$imgrs = new ImageResizer($tmpname, $mimetype);
$img = $imgrs->get_image();
if (!empty($img)) {
$imgrs->resize_image(array('w' => $resizeonuploadmaxwidth, 'h' => $resizeonuploadmaxheight), $mimetype); //auto
$saveresize = $imgrs->save_image($tmpname, $mimetype, 85);
if (!$saveresize) {
return array('error' => true, 'message' => get_string('problemresizing', 'artefact.file'));
}
$resized = true;
}
}
}
}
try {
$newid = ArtefactTypeFile::save_uploaded_file('userfile', $data, $userfileindex);
$newid = ArtefactTypeFile::save_uploaded_file('userfile', $data, $userfileindex, $resized);
}
catch (QuotaExceededException $e) {
prepare_upload_failed_message($result, $e, $parentfoldername, $originalname);
......@@ -815,6 +878,10 @@ function pieform_element_filebrowser_upload(Pieform $form, $element, $data) {
$result['message'] = get_string('fileuploadedas', 'artefact.file', $originalname, $data->title);
}
if ($resizeattempted && !$resized) {
$result['message'] .= get_string('insufficientmemoryforresize', 'artefact.file');
}
$result['highlight'] = $newid;
$result['uploaded'] = true;
$result['newlist'] = pieform_element_filebrowser_build_filelist($form, $element, $parentfolder, $newid);
......
......@@ -48,6 +48,15 @@ $string['confirmdeletefolder'] = 'Are you sure you want to delete this folder?';
$string['confirmdeletefolderandcontents'] = 'Are you sure you want to delete this folder and all its contents?';
$string['customagreement'] = 'Custom agreement';
$string['Date'] = 'Date';
$string['resizeonupload'] = 'Resize images on upload';
$string['resizeonuploaddescription'] = 'Automatically resize large images on upload';
$string['resizeonuploaduseroption'] = 'Display user option';
$string['resizeonuploaduseroptiondescription'] = 'Show users the option to enable or disable automatic resizing of large images when uploading.';
$string['resizeonuploadenable'] = 'Enable automatic resizing of large images';
$string['resizeonuploadenablefilebrowser'] = 'Enable automatic resizing of images larger than %sx%s px (recommended)';
$string['resizeonuploadmaxwidth'] = 'Maximum width';
$string['resizeonuploadmaxheight'] = 'Maximum height';
$string['resizeonuploadenabledescription'] = 'Resize images on upload if they exceed the maximum width and height settings.';
$string['defaultagreement'] = 'Default agreement';
$string['defaultquota'] = 'Default quota';
$string['defaultquotadescription'] = 'You can set the amount of disk space that new users will have as their quota here.';
......@@ -159,6 +168,7 @@ $string['usecustomagreement'] = 'Use custom agreement';
$string['youmustagreetothecopyrightnotice'] = 'You must agree to the copyright notice';
$string['fileuploadedtofolderas'] = '%s uploaded to %s as "%s"';
$string['fileuploadedas'] = '%s uploaded as "%s"';
$string['insufficientmemoryforresize'] = ' (Not enough memory available to resize the image. Consider resizing manually before uploading)';
// File types
......
<h3>Resize large images on upload</h3>
<p>If enabled, any images which are larger than the height and width specified will be resized to fit the size limit.</p>
<p>This is highly recommended for images intended for normal display in a web browser. Very large images (e.g. straight from a digital camera) are slow to load in the browser, and take up unnecessary disk space, quickly using up your quota.
There is also no discernable gain in quality when viewing on a typical monitor.</p>
<p>However, you may wish to upload the original <strong>without</strong> resizing if you are sharing an image for printing.</p>
<p>You can choose the default setting for this option on your Settings page.</p>
<h3>Resize images on upload - maximum image size</h3>
<p>Maximum image size specifies a maximum pixel height and width for a user’s uploaded images. All images uploaded will be resized to these dimensions if they exceed the maximum image dimensions and image resizing is enabled.</p>
......@@ -508,6 +508,9 @@ abstract class ArtefactTypeFileBase extends ArtefactType {
* Creates pieforms definition for forms on the my files, group files, etc. pages.
*/
public static function files_form($page='', $group=null, $institution=null, $folder=null, $highlight=null, $edit=null) {
global $USER;
$resizeonuploaduserdefault = $USER->get_account_preference('resizeonuploaduserdefault');
$folder = param_integer('folder', 0);
$edit = param_variable('edit', 0);
if (is_array($edit)) {
......@@ -542,6 +545,8 @@ abstract class ArtefactTypeFileBase extends ArtefactType {
'config' => array(
'upload' => true,
'uploadagreement' => get_config_plugin('artefact', 'file', 'uploadagreement'),
'resizeonuploaduseroption' => get_config_plugin('artefact', 'file', 'resizeonuploaduseroption'),
'resizeonuploaduserdefault' => $resizeonuploaduserdefault,
'createfolder' => true,
'edit' => true,
'select' => false,
......@@ -726,6 +731,8 @@ abstract class ArtefactTypeFileBase extends ArtefactType {
}
public static function blockconfig_filebrowser_element(&$instance, $default=array()) {
global $USER;
$resizeonuploaduserdefault = $USER->get_account_preference('resizeonuploaduserdefault');
return array(
'name' => 'filebrowser',
'type' => 'filebrowser',
......@@ -736,6 +743,8 @@ abstract class ArtefactTypeFileBase extends ArtefactType {
'page' => get_config('wwwroot') . 'view/blocks.php' . View::make_base_url(),
'config' => array(
'upload' => true,
'resizeonuploaduseroption' => get_config_plugin('artefact', 'file', 'resizeonuploaduseroption'),
'resizeonuploaduserdefault' => $resizeonuploaduserdefault,
'uploadagreement' => get_config_plugin('artefact', 'file', 'uploadagreement'),
'createfolder' => false,
'edit' => false,
......@@ -943,18 +952,24 @@ class ArtefactTypeFile extends ArtefactTypeFileBase {
* Takes the name of a file input.
* Returns false for no errors, or a string describing the error.
*/
public static function save_uploaded_file($inputname, $data, $inputindex=null) {
public static function save_uploaded_file($inputname, $data, $inputindex=null, $resized=false) {
require_once('uploadmanager.php');
$um = new upload_manager($inputname, false, $inputindex);
if ($error = $um->preprocess_file()) {
throw new UploadException($error);
}
if (isset($inputindex)) {
if ($resized) {
$um->file['size'][$inputindex] = filesize($um->file['tmp_name'][$inputindex]);
}
$size = $um->file['size'][$inputindex];
$tmpname = $um->file['tmp_name'][$inputindex];
$filetype = $um->file['type'][$inputindex];
}
else {
if ($resized) {
$um->file['size'] = filesize($um->file['tmp_name']);
}
$size = $um->file['size'];
$tmpname = $um->file['tmp_name'];
$filetype = $um->file['type'];
......@@ -1319,6 +1334,64 @@ class ArtefactTypeFile extends ArtefactTypeFileBase {
'collapsible' => true
);
// Option to resize images on upload
$resizeonuploadenable = get_config_plugin('artefact', 'file', 'resizeonuploadenable');
$resizeonuploaduseroption = get_config_plugin('artefact', 'file', 'resizeonuploaduseroption');
$currentmaxwidth = get_config_plugin('artefact', 'file', 'resizeonuploadmaxwidth');
$currentmaxheight = get_config_plugin('artefact', 'file', 'resizeonuploadmaxheight');
if (!isset($currentmaxwidth)) {
$currentmaxwidth = get_config('imagemaxwidth');
}
if (!isset($currentmaxheight)) {
$currentmaxheight = get_config('imagemaxheight');
}
$elements['resizeonuploadfieldset'] = array(
'type' => 'fieldset',
'legend' => get_string('resizeonupload', 'artefact.file'),
'elements' => array(
'resizeonuploaddescription' => array(
'value' => get_string('resizeonuploaddescription', 'artefact.file'),
),
'resizeonuploadenable' => array(
'type' => 'checkbox',
'title' => get_string('resizeonuploadenable', 'artefact.file'),
'defaultvalue' => $resizeonuploadenable,
'description' => get_string('resizeonuploadenabledescription', 'artefact.file'),
),
'resizeonuploaduseroption' => array(
'title' => get_string('resizeonuploaduseroption', 'artefact.file'),
'type' => 'checkbox',
'defaultvalue' => $resizeonuploaduseroption,
'description' => get_string('resizeonuploaduseroptiondescription', 'artefact.file'),
),
'resizeonuploadmaxwidth' => array(
'type' => 'text',
'size' => 4,
'suffix' => get_string('widthshort'),
'title' => get_string('resizeonuploadmaxwidth', 'artefact.file'),
'defaultvalue' => $currentmaxwidth,
'rules' => array(
'required' => true,
'integer' => true,
)
),
'resizeonuploadmaxheight' => array(
'type' => 'text',
'suffix' => get_string('heightshort'),
'size' => 4,
'title' => get_string('resizeonuploadmaxheight', 'artefact.file'),
'defaultvalue' => $currentmaxheight,
'rules' => array(
'required' => true,
'integer' => true,
),
'help' => true,
),
),
'collapsible' => true
);
// Profile icon size
$currentwidth = get_config_plugin('artefact', 'file', 'profileiconwidth');
$currentheight = get_config_plugin('artefact', 'file', 'profileiconheight');
......@@ -1406,6 +1479,10 @@ class ArtefactTypeFile extends ArtefactTypeFileBase {
set_config_plugin('artefact', 'file', 'profileiconheight', $values['profileiconheight']);
set_config_plugin('artefact', 'file', 'uploadagreement', $values['uploadagreement']);
set_config_plugin('artefact', 'file', 'usecustomagreement', $values['usecustomagreement']);
set_config_plugin('artefact', 'file', 'resizeonuploadenable', $values['resizeonuploadenable']);
set_config_plugin('artefact', 'file', 'resizeonuploaduseroption', $values['resizeonuploaduseroption']);
set_config_plugin('artefact', 'file', 'resizeonuploadmaxwidth', $values['resizeonuploadmaxwidth']);
set_config_plugin('artefact', 'file', 'resizeonuploadmaxheight', $values['resizeonuploadmaxheight']);
$data = new StdClass;
$data->name = 'uploadcopyright';
$data->content = $values['customagreement'];
......
......@@ -61,6 +61,15 @@
{if $config.uploadagreement}<script>setNodeAttribute('{$prefix}_userfile', 'disabled', true);</script>{/if}
</td>
</tr>
{if $config.resizeonuploaduseroption}
<tr id="{$prefix}_resizeonuploaduseroption" class="description">
<th></th>
<td>{str tag='resizeonuploadenablefilebrowser' section='artefact.file' arg1=$resizeonuploadmaxwidth arg2=$resizeonuploadmaxheight}
<input type="checkbox" name="{$prefix}_resizeonuploaduserenable" id="{$prefix}_resizeonuploaduserenable" {if $resizeonuploadenable && $config.resizeonuploaduserdefault}checked{/if}/>
{contextualhelp plugintype='artefact' pluginname='file' form='files_filebrowser' element='resizeonuploaduseroption'}
</td>
</tr>
{/if}
<tr class="uploadform">
<th></th>
<td id="{$prefix}_uploadsubmit_container">{* filebrowser.js may add a submit button in here even if config.submitbutton is off *}
......
......@@ -28,5 +28,5 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2011082200;
$config->release = '1.2.0';
$config->version = 2012050400;
$config->release = '1.2.1';
......@@ -94,3 +94,6 @@ $string['maildisableddescription'] = 'Sending of email to your account has been
$string['deleteaccount'] = 'Delete account';
$string['deleteaccountdescription'] = 'If you delete your account, all your content will be deleted permanently. You cannot get it back. Your profile information and your pages will no longer be visible to other users. The content of any forum posts you have written will still be visible, but your name will no longer be displayed.';
$string['accountdeleted'] = 'Your account has been deleted.';
$string['resizeonuploaduserdefault'] = 'Enable "Resize large images on upload" by default';
$string['resizeonuploaduserdefaultdescription'] = 'Tick this box to set the "Resize large images on upload" checkbox option to "on" by default when uploading files. Untick to have that checkbox option set to "off" by default.';
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2007 Catalyst IT Ltd (http://www.catalyst.net.nz)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage core
* @author Mike Kelly UAL <m.f.kelly@arts.ac.uk> Adapted from a class by Jarrod Oberto
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
*
*/
defined('INTERNAL') || die();
class ImageResizer {
private $image;
private $width;
private $height;
private $imageresized;
function __construct($filename, $mimetype){
$this->image = $this->open_image($filename, $mimetype);
if (!empty($this->image)) {
$this->width = imagesx($this->image);
$this->height = imagesy($this->image);
}
}
private function open_image($file, $mimetype){
if (!$this->set_memory_for_image($file)) {
return;
}
switch ($mimetype) {
case 'image/jpg':
case 'image/jpeg':
$img = imagecreatefromjpeg($file);
break;
case 'image/gif':
$img = imagecreatefromgif($file);
break;
case 'image/png':
$img = imagecreatefrompng($file);
break;
default:
$img = false;
break;
}
return $img;
}
public function resize_image($size, $mimetype, $option='auto'){
// Get optimal width and height based on $size
$newwidth = $size['w'];
$newheight = $size['h'];
$optionarray = $this->get_dimensions($newwidth, $newheight, $option);
$optimalwidth = $optionarray['optimalwidth'];
$optimalheight = $optionarray['optimalheight'];
$this->imageresized = imagecreatetruecolor($optimalwidth, $optimalheight);
if ($mimetype == 'image/png' || $mimetype == 'image/gif') {
// Create a new destination image which is completely
// transparent and turn off alpha blending for it, so that when
// the PNG source file is copied, the alpha channel is retained
// Thanks to http://alexle.net/archives/131
$background = imagecolorallocate($this->imageresized, 0, 0, 0);
imagecolortransparent($this->imageresized, $background);
imagealphablending($this->imageresized, false);
imagecopyresampled($this->imageresized, $this->image, 0, 0, 0, 0, $optimalwidth, $optimalheight, $this->width, $this->height);
imagesavealpha($this->imageresized, true);
}
else {
imagecopyresampled($this->imageresized, $this->image, 0, 0, 0, 0, $optimalwidth, $optimalheight, $this->width, $this->height);
}
if ($option == 'crop') {
$this->crop($optimalwidth, $optimalheight, $newwidth, $newheight);
}
imagedestroy($this->image);
}
private function get_dimensions($newwidth, $newheight, $option){
switch ($option) {
case 'exact':
$optimalwidth = $newwidth;
$optimalheight= $newheight;
break;
case 'byheight':
$optimalwidth = $this->get_size_by_fixed_height($newheight);
$optimalheight= $newheight;
break;
case 'bywidth':
$optimalwidth = $newwidth;
$optimalheight= $this->get_size_by_fixed_width($newwidth);
break;
case 'crop':
$optionarray = $this->get_optimal_crop($newwidth, $newheight);
$optimalwidth = $optionarray['optimalwidth'];
$optimalheight = $optionarray['optimalheight'];
break;
case 'auto':
default:
$optionarray = $this->get_size_by_auto($newwidth, $newheight);
$optimalwidth = $optionarray['optimalwidth'];
$optimalheight = $optionarray['optimalheight'];
break;
}
if ($option == 'auto' && ($optimalheight > $newheight || $optimalwidth > $newwidth)) {
// First attempt resize calculation not within requested limits. Find errant dimension and resize by that dimension.
if ($optimalheight > $newheight) {
$optionarray = $this->get_dimensions($newwidth, $newheight, 'byheight');
}
else {
$optionarray = $this->get_dimensions($newwidth, $newheight, 'bywidth');
}
$optimalwidth = $optionarray['optimalwidth'];
$optimalheight = $optionarray['optimalheight'];
}
return array('optimalwidth' => $optimalwidth, 'optimalheight' => $optimalheight);
}
private function get_size_by_fixed_height($newheight){
$ratio = $this->width / $this->height;
$newwidth = $newheight * $ratio;
return $newwidth;
}
private function get_size_by_fixed_width($newwidth){
$ratio = $this->height / $this->width;
$newheight = $newwidth * $ratio;
return $newheight;
}
private function get_size_by_auto($newwidth, $newheight){
if ($this->height < $this->width) {
// Image to be resized is wider (landscape)
$optimalwidth = $newwidth;
$optimalheight= $this->get_size_by_fixed_width($newwidth);
}
else if ($this->height > $this->width) {
// Image to be resized is taller (portrait)
$optimalwidth = $this->get_size_by_fixed_height($newheight);
$optimalheight= $newheight;
}
else {
// Image to be resized is a square
if ($newheight < $newwidth) {
$optimalwidth = $newwidth;
$optimalheight= $this->get_size_by_fixed_width($newwidth);
}
else if ($newheight > $newwidth) {
$optimalwidth = $this->get_size_by_fixed_height($newheight);
$optimalheight= $newheight;
}
else {
// Square being resized to a square
$optimalwidth = $newwidth;
$optimalheight= $newheight;
}
}
return array('optimalwidth' => $optimalwidth, 'optimalheight' => $optimalheight);
}
private function get_optimal_crop($newwidth, $newheight){
$heightratio = $this->height / $newheight;
$widthRatio = $this->width / $newwidth;
if ($heightratio < $widthRatio) {
$optimalratio = $heightratio;
}
else {
$optimalratio = $widthRatio;
}
$optimalheight = $this->height / $optimalratio;
$optimalwidth = $this->width / $optimalratio;
return array('optimalwidth' => $optimalwidth, 'optimalheight' => $optimalheight);
}
private function crop($optimalwidth, $optimalheight, $newwidth, $newheight){
// Find center - this will be used for the crop
$cropstartx = ($optimalwidth / 2) - ($newwidth /2);
$cropstarty = ($optimalheight/ 2) - ($newheight/2);
$crop = $this->imageresized;
// Now crop from center to exact requested size
$this->imageresized = imagecreatetruecolor($newwidth, $newheight);
imagecopyresampled($this->imageresized, $crop , 0, 0, $cropstartx, $cropstarty, $newwidth, $newheight , $newwidth, $newheight);
}
public function save_image($savepath, $mimetype, $imagequality='100') {
$saved = false;
switch ($mimetype) {
case 'image/jpg':
case 'image/jpeg':
if (imagetypes() & IMG_JPG) {
$saved = imagejpeg($this->imageresized, $savepath, $imagequality);
}
break;
case 'image/gif':
if (imagetypes() & IMG_GIF) {
$saved = imagegif($this->imageresized, $savepath);
}
break;
case 'image/png':
// Scale quality from 0-100 to 0-9
$scalequality = round(($imagequality/100) * 9);
// Invert quality setting as 0 is best, not 9
$invertscalequality = 9 - $scalequality;
if (imagetypes() & IMG_PNG) {
$saved = imagepng($this->imageresized, $savepath, $invertscalequality);
}
break;
default:
// No extension, no save.
break;
}
imagedestroy($this->imageresized);
return $saved;
}
private function set_memory_for_image($filename){
// See http://uk3.php.net/manual/en/function.imagecreatefromjpeg.php#64155
$imageinfo = getimagesize($filename);
$mimetype = $imageinfo['mime'];
if (isset($imageinfo['bits'])) {
$bits = $imageinfo['bits'];
}
else if ($mimetype == 'image/gif') {
$bits = 8;
}
if (isset($imageinfo['channels'])) {
$channels = $imageinfo['channels'];