/** ---------------------------------------- /** Image Resizing /** ----------------------------------------*/ function _image_resize($filename, $type = 'avatar', $axis = 'width') { global $PREFS; if ( ! class_exists('Image_lib')) { require PATH_CORE.'core.image_lib'.EXT; } $IM = new Image_lib(); if ($type == 'avatar') { $max_width = ($PREFS->ini('avatar_max_width') == '' OR $PREFS->ini('avatar_max_width') == 0) ? 100 : $PREFS->ini('avatar_max_width'); $max_height = ($PREFS->ini('avatar_max_height') == '' OR $PREFS->ini('avatar_max_height') == 0) ? 100 : $PREFS->ini('avatar_max_height'); $image_path = $PREFS->ini('avatar_path', TRUE).'uploads/'; } elseif ($type == 'photo') { $max_width = ($PREFS->ini('photo_max_width') == '' OR $PREFS->ini('photo_max_width') == 0) ? 100 : $PREFS->ini('photo_max_width'); $max_height = ($PREFS->ini('photo_max_height') == '' OR $PREFS->ini('photo_max_height') == 0) ? 100 : $PREFS->ini('photo_max_height'); $image_path = $PREFS->ini('photo_path', TRUE); } else { $max_width = ($PREFS->ini('sig_img_max_width') == '' OR $PREFS->ini('sig_img_max_width') == 0) ? 100 : $PREFS->ini('sig_img_max_width'); $max_height = ($PREFS->ini('sig_img_max_height') == '' OR $PREFS->ini('sig_img_max_height') == 0) ? 100 : $PREFS->ini('sig_img_max_height'); $image_path = $PREFS->ini('sig_img_path', TRUE); } $res = $IM->set_properties( array( 'resize_protocol' => $PREFS->ini('image_resize_protocol'), 'libpath' => $PREFS->ini('image_library_path'), 'maintain_ratio' => TRUE, 'master_dim' => $axis, 'file_path' => $image_path, 'file_name' => $filename, 'quality' => 75, 'dst_width' => $max_width, 'dst_height' => $max_height ) ); if ( ! $IM->image_resize()) { return FALSE; } return TRUE; }
/** ----------------------------------- /** Create image thumbnail /** -----------------------------------*/ function create_thumb() { global $IN, $DSP, $LANG, $PREFS, $LANG, $DB; if ($_POST['width_unit'] == 'percent') { $_POST['width'] = ceil($_POST['width'] / 100 * $_POST['width_orig']); } if ($_POST['height_unit'] == 'percent') { $_POST['height'] = ceil($_POST['height'] / 100 * $_POST['height_orig']); } foreach ($_POST as $key => $val) { ${$key} = $val; } //print_r($_POST); exit; if ($width == $width_orig and $height == $height_orig) { return $DSP->error_message($LANG->line('image_size_not_different')); } if ($width != $width_orig or $height_orig != $height) { $query = $DB->query("SELECT * FROM exp_upload_prefs WHERE id = '" . $DB->escape_str($id) . "'"); $thumb_prefix = $PREFS->ini('thumbnail_prefix') == '' ? 'thumb' : $PREFS->ini('thumbnail_prefix'); /** -------------------------------- /** Invoke the Image Lib Class /** --------------------------------*/ require PATH_CORE . 'core.image_lib' . EXT; $IM = new Image_lib(); /** -------------------------------- /** Resize the image /** --------------------------------*/ $res = $IM->set_properties(array('resize_protocol' => $PREFS->ini('image_resize_protocol'), 'libpath' => $PREFS->ini('image_library_path'), 'thumb_prefix' => $source == 'orig' ? '' : $thumb_prefix, 'file_path' => $query->row['server_path'], 'file_name' => $file_name, 'dst_width' => $width, 'dst_height' => $height, 'maintain_ratio' => FALSE)); if ($res === FALSE or !$IM->image_resize()) { return $IM->show_error(); } } $this->finalize_uploaded_file(array('id' => $id, 'field_group' => $field_group, 'orig_name' => $file_name, 'file_name' => $IM->thumb_name, 'is_image' => 1, 'step' => 2, 'source' => $source)); }