1

I am trying to resize an uploaded image from Codeigniter panel to the server, in this process when i try to overwrite the image i get a black background with the resized image in it (image attached) , please help me with this

New Image Created

My code is as follows :

move_uploaded_file($_FILES['img']['tmp_name'],"img".".".$extension);
$config['image_library'] = 'gd2';
$config['maintain_ratio'] = TRUE;
$config['create_thumb'] = False;
$config['overwrite'] = TRUE;
$config['width'] = 1000;
$config['height'] = 1000;
$config['quality'] = 100;
$config['source_image'] = "img".".".$extension;
$config['new_image'] = "img".".".$extension;
$this->image_lib->clear();
$this->image_lib->initialize($config);
$this->image_lib->resize();

Also is there any other way i can directly take the temp image and save with compression?

Thank You, Rebecca

Rebecca
  • 403
  • 2
  • 7
  • 29

2 Answers2

2

Please go through below, It will help your issue.

You can create another folder or new name for resize image. You are facing issue because while resizing image, the source image already in use. Hence either create new folder or change filename.

Create New Folder

$config['new_image'] = "path/to/new/folder/img".".".$extension;

Change New Image(Resized) name

$config['new_image'] = "newimg".".".$extension;

Let me know if it not works to you.

Alex Mac
  • 2,970
  • 1
  • 22
  • 39
  • this actually works well , but then this would include an extra code for unlinking, in place of that i was thinking of the above code... thanks anyways :) @shyam – Rebecca Jun 10 '17 at 09:09
0

Please go through below running solution as per your requirement.

if ($this->input->server('REQUEST_METHOD') === 'POST'):
    $this->load->library('image_lib');
    $path_parts = pathinfo($_FILES["file"]["name"]);
    $extension = $path_parts['extension'];
    move_uploaded_file($_FILES['file']['tmp_name'], "./uploads/img" . "." . $extension);
    $config['image_library'] = 'gd2';
    $config['maintain_ratio'] = TRUE;
    $config['create_thumb'] = False;
    $config['overwrite'] = TRUE;
    $config['width'] = 200;
    $config['height'] = 200;
    $config['quality'] = 100;
    $config['source_image'] = "./uploads/img" . "." . $extension;
    $this->image_lib->clear();
    $this->image_lib->initialize($config);
    $this->image_lib->resize();
endif;
Alex Mac
  • 2,970
  • 1
  • 22
  • 39
  • i removed the new_image as per the above code i get the following : The path to the image is not correct. Your server does not support the GD function required to process this type of image. Your server does not support the GD function required to process this type of image. – Rebecca Jun 10 '17 at 10:04
  • Please change path while storing and processing image, because it seems like permission issue in your root folder. I'm not sure but please try as above mentioned. – Alex Mac Jun 10 '17 at 10:12
  • i get the same image with black background... sorry previously it was my mistake due to wrong path... – Rebecca Jun 10 '17 at 10:14