• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GD2/image_lib working on live website, but not on localhost (XAMPP)

#1
[eluser]shadowmanwkp[/eluser]
Hi there, I've been scouring the internet for an answer, but I just can't seem to find one. My problem is with a controller that uses img_lib's resize function. There's an existing website I'm working on that displays the images that go through img_lib properly, but when I look at them through localhost, they show up as broken images. If I use <img> tags to point directly to the images they work absolutely fine, only the images that get go through the controller get broken.

Here's the code:

Code:
function resized() {
  $irrelevant_part_of_uri = "/images/resized/" . $this->uri->segment(3) . "/" . $this->uri->segment(4) . "/";
  $image_path = substr(uri_string(), strlen($irrelevant_part_of_uri));
  //$image_dimensions = getimagesize("public/" . $image_path);

   $config['image_library'] = 'gd2';
   $config['source_image'] = "public/" . $image_path;
   $config['create_thumb'] = FALSE;
   $config['maintain_ratio'] = TRUE;
   $config['width'] = $this->uri->segment(3);
   $config['height'] = $this->uri->segment(4);
   $config['dynamic_output'] = TRUE;
   $config['quality'] = 100;
   $this->load->library('image_lib', $config);
   $this->image_lib->resize();
}


Because the dev that made the website is gone, and I have no documentation, it took me a while to figure out the code:

- There's a controller images.php with the function resized()
- The images already exist and reside in <domain>/public/userfiles/images and its subfolders
- The image paths are pulled from a database, which I have running locally. These paths are put into <img> tags in their respective views
- I have no clue why 'public/' is concatenated in source_image, the dev might as well have put that part of the path in the database
- All images that need to be resized have the following urls <domain>/images/resized/<width><height>/actual/path/to/file.jpg
- The function looks at <width> and <height> and uses uri->segment in order to see the dimensions that need to be resized to
- Because dynamic_output is on, there's no actual folder that points to the image, but you can fool the <img> tags so you do display an image (just stick them in the folder hierarchy the src attribute specifies)
- It does not matter if I autoload image_lib, and call it through a different function (forgot the specifics...): I still get thrown an error
- According to netbeans, $image_dimensions wasn't used anywhere, so I commented it out, didn't seem to affect anything

Here's some more info using a non-existing image (if I use an existing one, the browser throws an error message because the image is broken):

Example URL:
http://<local domain>/images/resized/150/300/userfiles/images/products/asdf.jpg

Code:
echo $irrelevant_part_of_uri: /images/resized/150/300/
echo $image_path: userfiles/images/products/asdf.jpg
echo $this->image_lib->display_errors():
The path to the image is not correct.

Your server does not support the GD function required to process this type of image.

print_r($config):

Array
(
    [image_library] => GD2
    [source_image] => public/userfiles/images/products/asdf.jpg
    [create_thumb] =>
    [maintain_ratio] => 1
    [width] => 150
    [height] => 300
    [dynamic_output] => 1
    [quality] => 100
)

print_r(gd_info()):

Array
(
    [GD Version] => bundled (2.1.0 compatible)
    [FreeType Support] => 1
    [FreeType Linkage] => with freetype
    [T1Lib Support] =>
    [GIF Read Support] => 1
    [GIF Create Support] => 1
    [JPEG Support] => 1
    [PNG Support] => 1
    [WBMP Support] => 1
    [XPM Support] => 1
    [XBM Support] => 1
    [JIS-mapped Japanese Font Support] =>
)

phpinfo():

Core

PHP Version  5.5.11
max_execution_time 600
max_file_uploads 20
max_input_nesting_level  64
max_input_time 300
max_input_vars 1000
memory_limit 128M
output_buffering 4096
post_max_size  50000M
precision 14
realpath_cache_size 16k
upload_max_filesize 2000M

gd

GD Support  enabled
GD Version  bundled (2.1.0 compatible)
FreeType Support  enabled
FreeType Linkage  with freetype
FreeType Version  2.4.10
GIF Read Support  enabled
GIF Create Support  enabled
JPEG Support  enabled
libJPEG Version  9 compatible
PNG Support  enabled
libPNG Version  1.5.18
WBMP Support  enabled
XPM Support  enabled
libXpm Version  30411
XBM Support  enabled
WebP Support  enabled

And for good measure my operating system and software versions:

OS: Windows 8 pro - 64-bit
XAMPP 1.8.3
Codeigniter version: 1.7.3

Any help would be greatly appreciated!

#2
[eluser]Flemming[/eluser]
hey, did you find the solution?

Could it be that GD Lib isn't installed in XAMPP ?

#3
[eluser]shadowmanwkp[/eluser]
[quote author="Flemming" date="1409587227"]hey, did you find the solution?

Could it be that GD Lib isn't installed in XAMPP ? [/quote]

GD2 is installed with every XAMPP, the only thing you have to do in order to activate GD2 is uncomment some lines in the php.ini. In fact the phpinfo() I shared says that it is enabled and installed:

Code:
gd

GD Support  enabled
GD Version  bundled (2.1.0 compatible)

The problem still persists though, I now have put it on a separate live domain for testing where it works a-ok, it's just that either XAMPP, or codeigniter does not like running GD2 in a local environment.

#4
[eluser]Flemming[/eluser]
but what is this referring to in your OP ?

Code:
Your server does not support the GD function required to process this type of image.

sorry, am not a XAMPP user so was just taking a stab in the dark! :-)

#5
[eluser]InsiteFX[/eluser]
Make sure you also have php5 imagemagick installed, not just GD2

For some reason they do not mention this.

#6
[eluser]shadowmanwkp[/eluser]
[quote author="Flemming" date="1409596866"]but what is this referring to in your OP ?

Code:
Your server does not support the GD function required to process this type of image.

sorry, am not a XAMPP user so was just taking a stab in the dark! :-)
[/quote]

To me, that seems like a more generic error. Keep in mind that the image I'm using does not exist. If I did use a proper image, the browser would dump the error information into the image itself causing an error, with no way for me to read back the information I dumped.

[quote author="InsiteFX" date="1409608793"]Make sure you also have php5 imagemagick installed, not just GD2

For some reason they do not mention this.
[/quote]

Either I'm doing something wrong, or imagemagick refuses to work properly. I installed "ImageMagick-6.6.7-5-Q16-windows-dll.exe" on the computer and put the imagick dll in xampp's ext folder. After that I edited the php.ini to include php_imagick.dll, but it refuses to resize the image: the browser still shows dummy images. I uninstalled imagemagick and instead of choosing program files (x86)/imagemagick, I chose c:/imagemagick, but to no avail.

According to the phpinfo() at least imagick should work:

Code:
imagick

imagick module enabled
imagick module version  3.1.0
imagick classes  Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator
ImageMagick version  ImageMagick 6.6.7-5 2011-02-03 Q16 http://www.imagemagick.org
ImageMagick copyright  Copyright (C) 1999-2011 ImageMagick Studio LLC
ImageMagick release date  2011-02-03

However if I look at "environment" table of phpinfo(), it could be that it looks in the wrong folder, because the environment table contains both the old and the new path to imagemagick:

Code:
Environment

Path  C:\ImageMagick-6.6.7-Q16;C:\Program Files (x86)\ImageMagick-6.6.7-Q16;

Note: the imagemagick folder in program files does not exist anymore.

#7
[eluser]InsiteFX[/eluser]
Question? What OS are you running and if using xampp where did you install it to?

Ok, I see that you are running xampp. Xampp needs to be installed in the c:\ root not under Program Files (x86)

Xampp has problems if it is not installed in the c:\ root on Windows OS.

c:\xampp

Thats where it should be if your running on Windows, also if you place it in the root like above I can explain to you how to setup the Windows environment variables for it.

#8
[eluser]shadowmanwkp[/eluser]
[quote author="InsiteFX" date="1409733588"]Question? What OS are you running and if using xampp where did you install it to?

Ok, I see that you are running xampp. Xampp needs to be installed in the c:\ root not under Program Files (x86)

Xampp has problems if it is not installed in the c:\ root on Windows OS.

c:\xampp

Thats where it should be if your running on Windows, also if you place it in the root like above I can explain to you how to setup the Windows environment variables for it.
[/quote]

Already installed to c:\xampp, I've heard many problems about running it from x86 program files, especially on x64 vista systems and newer due to UAC. The operating system is windows 8 pro 64-bit (6.2 build 9200).

#9
[eluser]avenirer[/eluser]
I don't know if this helps you... https://community.apachefriends.org/f/vi...17&t=53258 I think they are talking about Xampp 1.8.3

#10
[eluser]InsiteFX[/eluser]
Setting Windows Environment varables:

Code:
1) Windows Control Panel
2) System and Security
3) On the left side click on Advanced system settings
4) On the bottom you will see a button Environment Variables click on that
5) In the bottom system variables edit the path, go to the end and add a ; semi-colon if it is not there then
    add c:\xammp;c:\xampp\php;

6) you can add other paths also, like for composer and Git.

If you still cannot get it working I have an image library here that someone on here wrote that uses the CI Image_lib


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.