-
Dec 29th, 2013, 06:39 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Resize an image using GD
I'm trying to use the PHP GD library to zoom an image to double it's original size. Images are always 320 x 256 and I want to display them at 640 x 512. I want to do it with PHP to get around Chrome's lack of support for "nearest-neighbor" resizing in CSS.
Where am I going wrong?
Code:
<!DOCTYPE HTML>
<html>
<header>
</header>
<body>
<?php
$filename = 'test1.jpg';
header('Content-Type: image/jpeg');
$source = imagecreatefromjpeg($filename);
$zoomed = imagecreatetruecolor(640,512);
imagecopyresized($zoomed,$source,0,0,0,0,640,512,320,256);
imagejpeg($zoomed);
imagedestroy($zoomed);
?>
</body>
</html>
I also tried using sprintf to output the file like this:
Code:
echo(sprintf("<img src='%s'/>",$zoomed));
I think this fails because $zoomed is an image, not a string, but - as you can probably tell - my PHP knowledge is very limited!
Thanks for your help.
-
Dec 29th, 2013, 12:40 PM
#2
Thread Starter
Fanatic Member
Re: Resize an image using GD
I think I've got there:
Code:
<?php
$source = imagecreatefromjpeg("image.jpg");
$zoomed = imagecreatetruecolor(640,512);
imagecopyresized($zoomed,$source,0,0,0,0,640,512,320,256);
imagejpeg($zoomed, "zoomed.jpg");
imagedestroy($zoomed);
?>
<img src="zoomed.jpg" />
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|