...

View Full Version : GD help



jeromepelletier
06-24-2006, 02:43 PM
I wasnt sure which topic this goes under, since its php related i was guessing here.

How do you resize a image then save to another file, here is my code




<?php

header("Content-type: image/gif");
include('connect.php');
$img_width = $img_height = 50;

$img = imagecreatetruecolor($img_width, $img_height);

for ($y = 0; $y < $img_height; $y++) {

for ($x = 0; $x < $img_width; $x++) {

$cored=rand(1,100);
$coblue=rand(1,100);
$cogreen=rand(50,100);

$pix_color = imagecolorallocate($img, $cored, $coblue, $cogreen);

imagesetpixel($img, $x, $y, $pix_color);
}
}

imagegif($img);

imagedestroy($img);

?>

how would i, resize this, or "zoom in" on it to make it a 500 by 500 lets say, and then save it to somepic.gif

Thanks

vinyl-junkie
06-24-2006, 05:24 PM
If you want an easy way to resize images and save them to a library, use this script (http://www.nuonce.net/code-library/1084672916.html). It looks like it would be pretty easy to use.

jeromepelletier
06-24-2006, 06:05 PM
If you want an easy way to resize images and save them to a library, use this script (http://www.nuonce.net/code-library/1084672916.html). It looks like it would be pretty easy to use.
yeah, i found that one, i just dont understand it

vinyl-junkie
06-24-2006, 07:08 PM
No problem. I went ahead and tested it on my server, just to make sure I understood it myself. :)

As the documentation states, there are four parameters that you must set prior to calling this routine. To quote it here:


You call it like so:
resizeImage ($src, $dest, $newHeight, $newWidth)

$src = Source File
$dest = Destination, if left blank, will print to any web browswer
$newHeight = New Height of file. If left blank, will auto proporationate to newWidth
$newWidth = New Width of file. If left blank, will auto proporationate to newHeight
Note that the variable in red was a misprint on that web page's instructions, which I have corrected above.

Here is an example of how I set the parameters, then called this function:


$src = "http://www.napathon.net/images/PatWongAnimation.gif";
$dest = "/home/username/public_html/test/PatWongAnimationTemp.gif";
$newHeight = 500;
$newWidth = 500;

resizeImage ($src, $dest, $newHeight, $newWidth);
I did find, however, when I ran this that there is a slight correction in their code that needs to be made.

Find this code at the bottom of the page:


imagedestroy ($srcimg);
imagedestroy ($destimg);
and correct it like so:


if (!$dest) {
imagedestroy ($srcimg);
imagedestroy ($destimg);
}

jeromepelletier
06-24-2006, 09:57 PM
hmmm i was hoping i could just use 1 line like newimage=resize(200%) that would be so much easier XD

vinyl-junkie
06-25-2006, 12:08 AM
If you know what size and type of image you will always have to resize, the function that I gave you is probably overkill and could be reduced to something a whole lot smaller. I'll let someone with time on their hands figure out how to do that. This one works, and will be the one I'll use should I ever find myself in need of such a routine. Anyway, you can always use include code to reference the function itself, so your main script isn't so cluttered.

jeromepelletier
06-29-2006, 07:01 PM
dont know if im right or not but, wouldnt this be the only line I need?



ImageCopyResized($destimg,$srcimg,0,0,0,0,$width,$height,ImageSX($srcimg),ImageSY($srcimg));

vinyl-junkie
06-30-2006, 05:45 AM
Try it and see. :)

jeromepelletier
07-06-2006, 06:41 PM
i did try..and saw nothing xD

jeromepelletier
07-13-2006, 07:32 PM
****bump*****



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum