Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10

Thread: GD help

  1. #1
    Regular Coder
    Join Date
    Jul 2005
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts

    GD help

    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 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

  • #2
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,073
    Thanks
    2
    Thanked 22 Times in 22 Posts
    If you want an easy way to resize images and save them to a library, use this script. It looks like it would be pretty easy to use.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!

  • #3
    Regular Coder
    Join Date
    Jul 2005
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by vinyl-junkie
    If you want an easy way to resize images and save them to a library, use this script. It looks like it would be pretty easy to use.
    yeah, i found that one, i just dont understand it

  • #4
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,073
    Thanks
    2
    Thanked 22 Times in 22 Posts
    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:

    Code:
    $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:

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

    Code:
    	if (!$dest) { 
                              imagedestroy ($srcimg);
                              imagedestroy ($destimg);
    	}
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!

  • #5
    Regular Coder
    Join Date
    Jul 2005
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hmmm i was hoping i could just use 1 line like newimage=resize(200%) that would be so much easier XD

  • #6
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,073
    Thanks
    2
    Thanked 22 Times in 22 Posts
    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.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!

  • #7
    Regular Coder
    Join Date
    Jul 2005
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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));

  • #8
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,073
    Thanks
    2
    Thanked 22 Times in 22 Posts
    Try it and see.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!

  • #9
    Regular Coder
    Join Date
    Jul 2005
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i did try..and saw nothing xD

  • #10
    Regular Coder
    Join Date
    Jul 2005
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ****bump*****


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •