/** * Lets you know if the image at the given path is too large for the server to process. We run * this to avoid crashing when GD tries to process large images. * * When this function returns an array, that array has two components: * * - image_size - number of btyes of memory that we predict the uncompressed image will need AND * - size_limit - the maximum size in bytes of what we believe we can process with GD * * @param string $path A file path * @return mixed array describing image_size and size_limit of too big image or boolean FALSE */ function image_is_too_big($path) { if (!imagemagick_available()) { $image_info = getimagesize($path); $mem_usage = memory_get_usage(); $mem_limit = get_php_size_setting_as_bytes('memory_limit'); if ($image_info[2] == IMAGETYPE_JPEG) { $image_size = $image_info[0] * $image_info[1] * $image_info['channels'] * $image_info['bits'] / 8; $ratio = 0.5; } elseif ($image_info[2] == IMAGETYPE_GIF) { $bits = $image_info['bits'] < 6 ? 6 : $image_info['bits']; $image_size = $image_info[0] * $image_info[1] * $image_info['channels'] * $bits / 8; $ratio = 0.95; } elseif ($image_info[2] == IMAGETYPE_PNG) { $image_size = $image_info[0] * $image_info[1] * 4 * 16 / 8; $ratio = 0.79; } if ($image_size / ($mem_limit - $mem_usage) > $ratio) { return array('image_size' => $image_size, 'size_limit' => ($mem_limit - $mem_usage) * $ratio); } } return FALSE; }
function on_every_time_order() { $order = array(); if ($this->_is_element('cancel_text')) { $order[] = 'cancel_text'; } $order[] = 'source_selection_note'; $order[] = 'destination_selection_note'; for ($i = 1; $i <= $this->max_upload_number; $i++) { $name = 'upload_' . $i; $this->add_element($name, 'image_upload', array('max_width' => REASON_STANDARD_MAX_IMAGE_WIDTH, 'max_height' => REASON_STANDARD_MAX_IMAGE_HEIGHT)); $this->add_element($name . '_filename', 'hidden', array('userland_changeable' => true)); if (!imagemagick_available()) { $size = get_approx_max_image_size(); $this->set_comments($name, 'Images with resolutions over ' . $size['res'] . ' or ' . $size['mps'] . ' MPs may cause errors'); } $order[] = $name; } $this->set_order($order); }
function on_every_time_order() { $order = array(); if ($this->_is_element('cancel_text')) { $order[] = 'cancel_text'; } $order[] = 'source_selection_note'; $order[] = 'destination_selection_note'; for ($i = 1; $i <= $this->max_upload_number; $i++) { $name = 'upload_' . $i; $this->add_element($name, 'image_upload', array('max_width' => REASON_STANDARD_MAX_IMAGE_WIDTH, 'max_height' => REASON_STANDARD_MAX_IMAGE_HEIGHT)); $this->add_element($name . '_filename', 'hidden', array('userland_changeable' => true)); if (!imagemagick_available()) { $size = get_approx_max_image_size(); $this->set_comments($name, 'Images with resolutions over ' . $size['res'] . ' or ' . $size['mps'] . ' MPs may cause errors'); } $order[] = $name; } /* * add the ignore image size check option to allow upload of images of any size */ $this->add_element('ignore_min_img_size_check', 'checkbox', array('description' => 'Ignore minimum image size check.')); $this->set_display_name('ignore_min_img_size_check', ' '); $order[] = 'ignore_min_img_size_check'; $this->set_order($order); }