Codeigniter resize issue after transferring server - php

The code was working like a charm for me. But I have now transferred the files from one server to another, and it is not working now. The image is being uploaded (original) -> image.jpg but the other two images after resize thumb_image.jpg and featured_image.jpg are not being uploaded. I dont know what the problem is.
I went through the error log and I see these 3 lines of codes
ERROR - 2013-09-08 17:38:26 --> PNG images are not supported.
ERROR - 2013-09-08 17:38:26 --> The path to the image is not correct.
ERROR - 2013-09-08 17:38:26 --> Your server does not support the GD function required to process this type of image.
I dont understand whats the issue with the image path and why does it says PNG images are not supported as it was working perfectly fine.
The resize code is
public function resizeIMG($imagePath, $filename){
$this->load->library('image_lib');
$configThumb['image_library'] = 'gd2';
$configThumb['source_image'] = $imagePath;
$configThumb['create_thumb'] = FALSE;
$configThumb['new_image'] = 'thumb_'.$filename;
$configThumb['maintain_ratio'] = TRUE;
$configThumb['width'] = 260;
$configThumb['height'] = 215;
$configFeatured['image_library'] = 'gd2';
$configFeatured['source_image'] = $imagePath;
$configFeatured['create_thumb'] = FALSE;
$configFeatured['new_image'] = 'featured_'.$filename;
$configFeatured['maintain_ratio'] = TRUE;
$configFeatured['width'] = 800;
$configFeatured['height'] = 500;
$configCropFeatured['image_library'] = 'gd2';
$configCropFeatured['source_image'] = './uploads/featured_'.$filename;
$configCropFeatured['x_axis'] = '0';
$configCropFeatured['y_axis'] = '0';
$configCropFeatured['create_thumb'] = FALSE;
$configCropFeatured['new_image'] = 'featured_'.$filename;
$configCropFeatured['maintain_ratio'] = FALSE;
$configCropFeatured['width'] = 720;
$configCropFeatured['height'] = 250;
$this->image_lib->initialize($configThumb);
$this->image_lib->resize();
$this->image_lib->initialize($configFeatured);
$this->image_lib->resize();
$this->image_lib->initialize($configCropFeatured);
$this->image_lib->crop();
}

The logs say Your server does not support the GD function required to process this type of image. which means that your server host has not enabled the GD library (or possibly banned the functions you are using for whatever reason)
You will need to contact your webhost to see if they can enable GD. If not, you will need to convert your application to use a different library. You can find out which libraries are available by running phpinfo() inside a PHP script. If GD is disabled, it's most likely that instead, ImageMagick is turned on - you can check out that page and you will be able to convert your application to use ImageMagick once you understand the basic functions. Please make sure that ImageMagick (or imagick) is somewhere in phpinfo(). If not, you're probably best asking your host to enable either of the plugins.

Related

typo3 image - using only GDLib?

I need some help with TYPO3 images - i have in image configuration both ImageMagick and GDLib enabled. Lately, on my hosting ImageMagic installation is no longer available and now i upload images but are not displayed on website. Is it possible to use only GDLib and what should I change in localconf.php.
Below is what i have now:
$TYPO3_CONF_VARS['BE']['disable_exec_function'] = '0';
$TYPO3_CONF_VARS['GFX']['gdlib_png'] = '0';
$TYPO3_CONF_VARS['GFX']['im_combine_filename'] = 'composite';
$TYPO3_CONF_VARS['GFX']['im_path'] = '/usr/bin/';
$TYPO3_CONF_VARS['GFX']['im_version_5'] = 'im6';
$TYPO3_CONF_VARS['GFX']['im_no_effects']='1'; //recommended in case using IM5+
$TYPO3_CONF_VARS['GFX']['im_v5effects']='0'; //recommended in case using IM5+
$TYPO3_CONF_VARS ['GFX'] ['JPG_Quality'] = '65';
$TYPO3_CONF_VARS ['FE'] ['compression level'] = '9';
$TYPO3_CONF_VARS ['BE'] ['compression level'] = '5';
This change will affect existing images?
Thanks for your help
TYPO3 can also use GraphicsMagick but if your hoster disabled ImageMagick then probably you have also no way to use GraphicsMagick.
Anyway you can try to enable GraphicsMagick with:
$TYPO3_CONF_VARS['GFX']['im_version_5'] = 'gm';
If that fails then the only solution is to change hoster or install extension "jb_gd_resize". This extension changes TYPO3 to use GDLib.

How can i select whole folder with pictures in codeigniter?

I have a project in which i need to select whole folder with pictures inside it, and then do a transformation on all of the pictures inside the folder. Something similar like scripts in photoshop for massive pictures adjustment.
Check PHP's scandir() function
Loop through the results of your directory and do your image manipulation on each item.
Well, CodeIgniters Manual does have some helper functions, but I'm not using them myself.
Personally, I'm more comfortable using the DirectoryIterator PHP supplies you with. Combining this with CodeIgniters Image Manipulation Class you can achieve some pretty nifty handling of your image processing:
$images = array("jpg", "png", "bmp"); // Just to make sure that we get image files
foreach(new DirectoryIterator("/path/to/images/") as $file)
{
if( $file->isFile() && in_array($file->getExtension(), $images) )
{
$config['image_library'] = 'imagemagick';
$config['library_path'] = 'usr/bin/local/';
$config['source_image'] = $file->getPathname();
$config['new_image'] = $file->getPathname(); //Overwriting the source image
$config['maintain_ratio'] = TRUE;
$config['width'] = 75;
$config['height'] = 50;
$this->load->library('image_lib', $config);
$this->image_lib->resize();
}
}
Or do some image processing of your own choice.
If you are using linux, you can mass edit the images using ImageMagick's mogrify command.
Example: mogrify -resize 150x150 *.jpg
Result: all images were resized to 150x150
There is also a PHP class that deals with ImageMagick functionality in PEAR.
I don't think there is a function that could perform multiple image processing. But you could select files with glob() and then do your process in a loop ?

CodeIgniter - Convert GIF to JPG? Possible?

I am looking to accomplish this in CodeIgniter specifically.
The PHP App I am coding allows a user to upload either a jpg or an animated gif image. On the next step I want to allow the user to use jCrop to crop a few different size thumbnails. This would require me to convert a new copy of the animated gif to a jpg. My code works fine with uploaded jpg images, but creates a broken image for gif files. Is what I am trying to do possible?
My Code:
// Create image to crop
$config['image_library'] = 'ImageMagick';
$config['library_path'] = '/usr/bin';
$config['source_image'] = $this->config->item('upload_dir_path') . $file_path . 'original.' . $file_ext;
chmod($config['source_image'], 0777);
$config['new_image'] = $this->config->item('upload_dir_path') . $file_path . 'crop-me.jpg';
$this->image_lib->initialize($config);
$this->image_lib->resize();
For those interested in my solution, I simply used the built in GD PHP functions. I have little experience dealing with gif files so I was expecting this to be difficult. The fact of the matter is the CodeIgniter Image_lib and extended library (Which I never got to work properly) is overkill for this.
Here is what I used:
$image = imagecreatefromgif($path_to_gif_image);
imagejpeg($image, $output_path_with_jpg_extension);
Very easy and worked perfectly for what I needed.

How can I resize my image?

This is my image uploading and resizing code in codeigniter.But in my client's server the image is uploaded but not create a resized image into a folder
if($imgwidth >= 1025 && $imgheight >= 650)
{
$epld=explode('.',$ex);
$filename=date("mdyHis").".".$epld[1];
$uploaddir = './bg_images/';
$file = $uploaddir . basename($filename);
if(move_uploaded_file($_FILES['file']['tmp_name'],"./bg_images/".$filename))
{
$this->load->library('image_lib');
$config['image_library'] = 'gd2';
$config['source_image'] = $file ;
$config['maintain_ratio'] = FALSE;
$this->image_lib->initialize($config);
$this->md_image->resize_image('./bg_images/'.$filename,1025,650,'./bg_images/thumbs/'.$filename);
}
}
The bg_images is the folder name and the md_image is the library used for resizing
I can not spot any errors in your code.
Make sure you have gdlib installed by uploading a script with the following content:
<?php
echo phpinfo();
?>
The Script shows your php configuration.
Search for "gd" with your browser's search function. No mention of "gd" would mean that you are missing this library, but you need it for image manipulation.
does the ./bg_images/thumbs/ folder exist on the file system?
As far as I remember, gdlib would not create folder itself. If the folder is missing, create it yourself (remember to give it the right permissions, the server / php process needs write permission (most likely www-data))
If all this doesn't help, ask your client's admin for access to the error logs.

Codeigniter Blue Hue

UPDATE: THE ANSWER IS USE THE GD2 LIBRARY, DOH!
I am working with Codeigniter's image manipulation library to resize some photos. Unfortunately, they are producing a blue tint or hue to the photos. Not sure why this is and needed to see if it was something I am doing. Here is the code I am using to create the thumb's. Let me know if you want to see image links, and I will upload them somewhere.
$this->load->library('image_lib');
$config['image_library'] = 'GD';
$config['source_image'] ="images/IMG_0007.jpg";
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = '450';
$config['height'] = '450';
$this->image_lib->initialize($config);
if(!$this->image_lib->resize())
{
echo $this->image_lib->display_errors();
}
I strongly recommend you to use ImageMagick for image resizing. It respects color profiles, is slightly faster, less memory hungry and generally produces better quality. See this question:
How to stop GD2 from washing away the colors upon resizing images?
If you do not have ImageMagick installed, this may be of help:
http://ferdychristant.com/blog//archive/DOMM-8GAFGL

Categories