Welcome Guest, Not a member yet? Register   Sign In
Image resize on JPGs - resized image appears as tiny thumb on black background
#1

[eluser]w1ntermut3[/eluser]
Using resize as:

Code:
$config['image_library'] = 'gd2';
$config['source_image'] = $save_path. $upload_data['file_name'];
$config['maintain_ratio'] = TRUE;
$config['master_dim'] = 'width';
$config['width'] = 250;
$config['height'] = 100000;

$ci->image_lib->initialize($config);
if ( ! $ci->image_lib->resize()){
echo $ci->image_lib->display_errors();
}
$ci->image_lib->resize();
$ci->image_lib->clear();

I upload a 797 x 1024 image, and expect it to be resized down to 250 wide, maintaining aspect ratio. What I get is this:

http://www.bencasey.co.uk/resize-wrong.jpg

Well, it's got the aspect ratio right I guess. The image IS 250 wide, and a corresponding height. However, most of the image is, in fact, not my image at all but a large expanse of black, with the actual image - at the correct aspect ratio - confined to a tiny thumb area at the top.

There seem to be a few posts regarding unwanted black backgrounds, but they're working with GIF/PNG transparency. This is on JPGs.

Why is it doing this, and how do I stop it?

#2

[eluser]ludo31[/eluser]
I think in my opinion You do that with Css
#3

[eluser]w1ntermut3[/eluser]
What? I don't even... never mind. Thanks for your input.
#4

[eluser]meigwilym[/eluser]
Have you tried it without specifying the height?

I've had niggles like this with image resizing before, ofgen it's to do with the server.

Mei
#5

[eluser]w1ntermut3[/eluser]
Yep, tried with no height set, with height set to 100, with no master_dim set, with master_dim set to auto, with maintain_ratio true and false... I just get a variation on the theme of "resized original on a black background".

I've given up and done it natively, BTW. This works fine:

Code:
$canvas = imagecreatetruecolor($new_width, $new_height);
$source = imagecreatefromjpeg($saved_file_full_path);
$success = imagecopyresized($canvas, $source, 0, 0, 0, 0, $new_width, $new_height, $upload_width, $upload_height);
imagejpeg($canvas, $saved_file_full_path);




Theme © iAndrew 2016 - Forum software by © MyBB