NameSilo

Phase 2: Resizing Images on Server

SpaceshipSpaceship
SpaceshipSpaceship
SpaceshipSpaceship
Watch

user-7256

VIP Member
Impact
111
Hey all,

Thanks for the great help with the uploading; I've just gone and revised *everything*. So now, they upload. Yay.

AND they resize, too! :tu:

...but they're black boxes.

Here's my code:

PHP:
// Resample
		$image_resized = imagecreatetruecolor($new_width, $new_height);
		$image = imagecreatefromjpeg($uploadfile2);
		if ($image === false) { die ('Unable to open image'); }
		if (!imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width, $new_height, $imgsize[0], $imgsize[1]))
		{
			die("Error");
		}
		else
		{
			imagejpeg($image_resized, $uploadfile2, 100);
		}

Now, I know it has something to do with imagecreatetruecolor because PHP.net says it makes a black image with those dimensions, then you "draw" over it (I assume) by doing imagecreatefromjpeg after that, then resample with the imagecopyresampled function at the end.

These come more directly from PHP.net than my last code snippets; so it's more accurate... yet I still get black boxes once resized.

ANY help appreciated. I promise. :)

-Matt
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Chulium, thanks :)

The image looks aliased because of the function imagecopyresized, which does a resize without resampling, and hence results in the jaggies.

I'm guessing that it works because a simple resize takes far less memory than an interpolated (resampled) resize.

If you're inclined, I'd still recommend SSHing in and seeing what the command line prints out for the version called with imagecopyresampled. OTOH, if the results of the aliased version are satisfactory to your needs, I'd say the problem is solved.
 
0
•••
Well... almost. It *is* my photography portfolio, after all, and I'm not just making thumbnails; I'm making the larger but not full size version of my pics, too... and having alias there makes it look kinda bad.

I'll experiment with the memory allocation... and see if I can't really get it to work.

Thanks :)
 
0
•••
This is a beautiful day.

I added the ini_set function to set the memory limit to 32MB, and then changed the imagecopyresized function to imagecopyresampled - and it works great!

Thanks :)
 
0
•••
Hey, excellent! :kickass:

(I knew we'd get this solved one way or another)
 
0
•••
Olitt — high-converting AI websites, only from $1/moOlitt — high-converting AI websites, only from $1/mo

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com
Catchy
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back