0

I am trying to do flip operation in CodeIgniter I have found a code for image flip in php using codeigniter libraries First I uploaded image to a path, here is the coding of controller for this purpose:

$config['upload_path'] = 'D:/xampp/htdocs/ImageTools/assets/images/pages/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$this->load->library('image_lib');
$this->image_lib->initialize($config);
$this->image_lib->clear();
$this->load->library('upload',$config);
if(!$this->upload->do_upload()){
$errors = array('error' => $this->upload->display_errors());
$post_image='noimage.jpg';
}else{
$file_data = $this->upload->data();
$data['img'] = base_url().'assets/images/pages/'.$file_data['file_name'];
$this->load->view('pages/inverted',$data);

I tried to do the invert operation here but couldn't succeeded then tried to invert the uploaded image, done the coding in view file by passing this uploaded image to view:

<?php $img;?>
<?php
$this->image_lib->clear();
$config=array();
$config['image_library'] = 'gd2';
$config['source_image'] = $img;
$config['create_thumb'] = TRUE;
$config['rotation_angle'] = 'hor';
$this->load->library('image_lib');
$this->image_lib->initialize($config);
$this->load->library('upload',$config);
$this->image_lib->rotate();                    
if ( ! $this->image_lib->rotate())
{
echo $this->image_lib->display_errors();
}
if(!$this->upload->do_upload()){
$errors = array('error' => $this->upload->display_errors());
$post_image='noimage.jpg';
}
else{
$file_data = $this->upload->data();
$data = base_url().'/assets/images/pages/'.$file_data['file_name'];
}              
?>
mareena
  • 93
  • 1
  • 10
  • 1
    Don't really know how to explain it better than the error message and [the manual](http://php.net/manual/en/function.imageflip.php) does. The first argument needs to be an image resource, while you're passing in a URL as a string. – Magnus Eriksson Jul 03 '18 at 14:05
  • Do you have any solution? – mareena Jul 03 '18 at 14:17
  • Pass an image resource as the first argument instead of a string. If you read the manual for the function, there's even an example on how. – Magnus Eriksson Jul 03 '18 at 14:49
  • first off `D:/xampp/htdocs/ImageTools/assets/images/pages/` will never be valid in a server environment. there is a way to make it valid for all environments `./ImageTools/assets/images/pages/` and indeed you need to pass a resource. the issue with that is that you need to know which type of image you have ... png, jpg, .etc. It would be alot easier if you just user CI's included image library. – Alex Jul 03 '18 at 23:08
  • I have tried that but that is also creating problem. – mareena Jul 03 '18 at 23:46
  • @Alex I have edited the complete question please take a look. – mareena Jul 04 '18 at 00:01
  • And what is the exact issue now? – Alex Jul 04 '18 at 01:11
  • It is not working there are mistakes in the code that image src is not correct.Please check the code. how to display the rotated image – mareena Jul 04 '18 at 10:41
  • @Alex can you tell me the right code for implementing image flip in php, I have seen the code on the website but don't know how to flip an image through this code? – mareena Jul 04 '18 at 12:57

1 Answers1

0

First off D:/xampp/htdocs/ImageTools/assets/images/pages/ will never be valid in a server environment. There is a way to make it valid for all environments like so:

$config['upload_path'] = './ImageTools/assets/images/pages/';

(there are other ways but this is the one in the CI docs)

If the folder ImageTools is actually imagetools then that needs to be used in the above example; Linux is case sensitive.

Therefore, following the docs, you can do:

$upload['upload_path'] = './ImageTools/assets/images/pages/';
$upload['allowed_types'] = 'gif|jpg|png';

$this->load->library('upload', $upload);

if (!$this->upload->do_upload('userfile')) {
    show_error($this->upload->display_errors());
}

$this->load->library('image_lib');

$config['image_library'] = 'gd2';
$config['source_image'] = $this->upload->data('full_path');
$config['rotation_angle'] = 'hor'; // or whatever

$this->image_lib->initialize($config);

if (!$this->image_lib->rotate()) {
    show_error($this->image_lib->display_errors());
}

$img_path = base_url() . '/assets/images/pages/' . $this->upload->data('file_name');

echo "<img src='{$img_path}' width='auto' height='200'>";
Alex
  • 8,769
  • 7
  • 33
  • 77
  • can you help me in another task? – mareena Jul 06 '18 at 23:13
  • Perhaps. Start another question and since you are relatively new just make sure to follow stacks guidelines as downvotes and closings are commonplace. – Alex Jul 06 '18 at 23:15
  • started already, link: https://stackoverflow.com/questions/51207172/how-to-load-data-to-a-particular-section-of-the-page-without-refreshing-the-whol/51207312?noredirect=1#comment89397973_51207312 – mareena Jul 06 '18 at 23:18