Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function insert() {
- $data = array();
- /* Uploading Profile Images */
- $imagePath = realpath(APPPATH . '../assets/images/');
- $logo = $_FILES['logo']['tmp_name'];
- $favicon = $_FILES['favicon']['tmp_name'];
- if ($logo !== "") {
- $config['upload_path'] = $imagePath;
- $config['allowed_types'] = 'jpg|png|jpeg|gif';
- $config['file_name'] = date('Ymd_his_') . rand(10, 99) . rand(10, 99) . rand(10, 99);
- $this->load->library('upload', $config);
- if ($this->upload->do_upload('logo')) {
- $uploadData = $this->upload->data();
- $data['logo'] = $uploadData['file_name'];
- }
- $config['image_library'] = 'gd2';
- $config['source_image'] = $uploadData['full_path'];
- $config['new_image'] = $imagePath . '/crop';
- $config['quality'] = '100%';
- $config['maintain_ratio'] = FALSE;
- //Set cropping for y or x axis, depending on image orientation
- if ($uploadData['image_width'] > $uploadData['image_height']) {
- $config['width'] = $uploadData['image_height'];
- $config['height'] = $uploadData['image_height'];
- $config['x_axis'] = (($uploadData['image_width'] / 2) - ($config['width'] / 2));
- } else {
- $config['height'] = $uploadData['image_width'];
- $config['width'] = $uploadData['image_width'];
- $config['y_axis'] = (($uploadData['image_height'] / 2) - ($config['height'] / 2));
- }
- $this->image_lib->clear();
- $this->image_lib->initialize($config);
- $this->image_lib->crop();
- $config['source_image'] = $imagePath . '/crop/' . $uploadData['file_name'];
- $config['new_image'] = $imagePath . '/final';
- $config['maintain_ratio'] = FALSE;
- $config['width'] = 250;
- $config['height'] = 250;
- $this->image_lib->clear();
- $this->image_lib->initialize($config);
- $this->image_lib->resize();
- /* Deleting Uploaded Image After Croping and Resizing */
- /* Why Deleting because it's saving space */
- unlink($uploadData['full_path']);
- }
- if ($favicon !== "") {
- $config['upload_path'] = $imagePath;
- $config['allowed_types'] = 'jpg|png|jpeg|gif';
- $config['file_name'] = date('Ymd_his_') . rand(10, 99) . rand(10, 99) . rand(10, 99);
- $this->load->library('upload', $config);
- if ($this->upload->do_upload('favicon')) {
- $uploadData = $this->upload->data();
- $data['favicon'] = $uploadData['file_name'];
- }
- $config['image_library'] = 'gd2';
- $config['source_image'] = $uploadData['full_path'];
- $config['new_image'] = $imagePath . '/crop';
- $config['quality'] = '100%';
- $config['maintain_ratio'] = FALSE;
- //Set cropping for y or x axis, depending on image orientation
- if ($uploadData['image_width'] > $uploadData['image_height']) {
- $config['width'] = $uploadData['image_height'];
- $config['height'] = $uploadData['image_height'];
- $config['x_axis'] = (($uploadData['image_width'] / 2) - ($config['width'] / 2));
- } else {
- $config['height'] = $uploadData['image_width'];
- $config['width'] = $uploadData['image_width'];
- $config['y_axis'] = (($uploadData['image_height'] / 2) - ($config['height'] / 2));
- }
- $this->image_lib->clear();
- $this->image_lib->initialize($config);
- $this->image_lib->crop();
- $config['source_image'] = $imagePath . '/crop/' . $uploadData['file_name'];
- $config['new_image'] = $imagePath . '/final';
- $config['maintain_ratio'] = FALSE;
- $config['width'] = 250;
- $config['height'] = 250;
- $this->image_lib->clear();
- $this->image_lib->initialize($config);
- $this->image_lib->resize();
- /* Deleting Uploaded Image After Croping and Resizing */
- /* Why Deleting because it's saving space */
- unlink($uploadData['full_path']);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement