Image Resize & Rotation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • infoseekar
    New Member
    • Mar 2008
    • 34

    Image Resize & Rotation

    Image Resize & Rotation

    Hi

    I have 2 scripts, one for Image rotation and other image resize and they both are working.

    Image resize scripts load the picture and resize it and Image rotation rotate the image by 90 deg. They are two differennt files i.e. resize.php and rotate.php.

    What I want to do is to combine both rotate.php & resize.php files, so when the script resized the image than it will call rotate script to rotate the image and display it on the screen.. I hope I am making sence.. I am finding hard to explain.. If u dont understand anything please let me know..
    *************** **********
    Code for rotate.php
    [php]<?php
    // File and rotation
    $filename = 'image.png';
    $degrees = 18;

    // Content type
    header('Content-type: image/png');

    // Load
    $source = imagecreatefrom png($filename);

    // Rotate
    $rotate = imagerotate($so urce, $degrees, 0);

    // Output
    imagepng($rotat e);
    ?>
    =============== =============
    Code for resize.php
    <?php
    $src_img = imagecreatefrom png('image.png' );
    $srcsize = getimagesize('i mage.png');
    $dest_x = 200;
    $dest_y = (200 / $srcsize[0]) * $srcsize[1];
    $dst_img = imagecreatetrue color($dest_x, $dest_y);
    imagecopyresamp led($dst_img, $src_img, 0, 0, 0, 0,
    $dest_x, $dest_y, $srcsize[0], $srcsize[1]);
    header("content-type: image/png");
    imagepng($dst_i mg);
    imagedestroy($s rc_img);
    imagedestroy($d st_img);
    ?>[/php]thanks

    Please enclose any code within the proper code tags. See the Posting Guidelines on how to do that.

    moderator
    Last edited by ronverdonk; Mar 5 '08, 12:59 PM. Reason: code within tags
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    Don't output $rotate and use it as:
    $src_img = $rotate;

    Comment

    • infoseekar
      New Member
      • Mar 2008
      • 34

      #3
      Originally posted by hsriat
      Don't output $rotate and use it as:
      $src_img = $rotate;
      well i changed the output "$src_img = $rotate;" but it still did not work... Just to let know there are two different files

      File 1 is reseize.php

      File 2 is rotate.php

      thanks

      Comment

      • hsriat
        Recognized Expert Top Contributor
        • Jan 2008
        • 1653

        #4
        [php]<?php
        $src_img = imagecreatefrom png('image.png' );
        $srcsize = getimagesize('i mage.png');
        $dest_x = 200;
        $dest_y = (200 / $srcsize[0]) * $srcsize[1];
        $dst_img = imagecreatetrue color($dest_x, $dest_y);
        imagecopyresamp led($dst_img, $src_img, 0, 0, 0, 0, $dest_x, $dest_y, $srcsize[0], $srcsize[1]);
        imagedestroy($s rc_img);

        //header("content-type: image/png");
        //imagepng($dst_i mg);
        //?><?php
        // File and rotation
        //$filename = 'image.png';
        $degrees = 18;

        // Load
        //$source = imagecreatefrom png($filename);

        // Rotate
        $rotate = imagerotate($ds t_img, $degrees, 0); //CHANGED
        imagedestroy($d st_img);

        // Content type
        header('Content-type: image/png');

        // Output
        imagepng($rotat e);
        imagedestroy($r otate);
        ?>[/php]
        See if this works.

        Comment

        • infoseekar
          New Member
          • Mar 2008
          • 34

          #5
          Originally posted by hsriat
          [php]<?php
          $src_img = imagecreatefrom png('image.png' );
          $srcsize = getimagesize('i mage.png');
          $dest_x = 200;
          $dest_y = (200 / $srcsize[0]) * $srcsize[1];
          $dst_img = imagecreatetrue color($dest_x, $dest_y);
          imagecopyresamp led($dst_img, $src_img, 0, 0, 0, 0, $dest_x, $dest_y, $srcsize[0], $srcsize[1]);
          imagedestroy($s rc_img);

          //header("content-type: image/png");
          //imagepng($dst_i mg);
          //?><?php
          // File and rotation
          //$filename = 'image.png';
          $degrees = 18;

          // Load
          //$source = imagecreatefrom png($filename);

          // Rotate
          $rotate = imagerotate($ds t_img, $degrees, 0); //CHANGED
          imagedestroy($d st_img);

          // Content type
          header('Content-type: image/png');

          // Output
          imagepng($rotat e);
          imagedestroy($r otate);
          ?>[/php]
          See if this works.

          A BIG Thanks to You.. I was working on this from last week.. Thanks very much.. Just one more question.. If I want to resize and rotate .jpg file, so I just replaced .png with .jpg, gif and so on.

          Thanks

          Comment

          • hsriat
            Recognized Expert Top Contributor
            • Jan 2008
            • 1653

            #6
            Originally posted by infoseekar
            A BIG Thanks to You.. I was working on this from last week.. Thanks very much..
            You are welcome.
            Originally posted by infoseekar
            Just one more question.. If I want to resize and rotate .jpg file, so I just replaced .png with .jpg, gif and so on.
            No, it won't work. You will have to first check which image it is, then apply the corrosponding imagecreatefrom XXX() function.
            [php]<?php
            $srcsize = getimagesize('i mage.png');
            switch ($srcsize[mime])
            {
            case ('image/gif'):
            $src_img = imagecreatefrom gif('image.gif' );
            break;
            case ('image/png'):
            $src_img = imagecreatefrom png('image.png' );
            break;
            case ('image/jpeg'):
            $src_img = imagecreatefrom jpeg('image.jpg ');
            break;
            default:
            return;
            }[/php]
            * make sure if its imagecreatefrom jpeg or imagecreatefrom jpg

            Comment

            • infoseekar
              New Member
              • Mar 2008
              • 34

              #7
              Originally posted by hsriat
              You are welcome.

              No, it won't work. You will have to first check which image it is, then apply the corrosponding imagecreatefrom XXX() function.
              [php]<?php
              $srcsize = getimagesize('i mage.png');
              switch ($srcsize[mime])
              {
              case ('image/gif'):
              $src_img = imagecreatefrom gif('image.gif' );
              break;
              case ('image/png'):
              $src_img = imagecreatefrom png('image.png' );
              break;
              case ('image/jpeg'):
              $src_img = imagecreatefrom jpeg('image.jpg ');
              break;
              default:
              return;
              }[/php]
              * make sure if its imagecreatefrom jpeg or imagecreatefrom jpg
              once again thank you.. i will give it a go

              Comment

              • infoseekar
                New Member
                • Mar 2008
                • 34

                #8
                Originally posted by infoseekar
                once again thank you.. i will give it a go
                Thanks for all your help

                Regards

                InfoSeekar

                Comment

                • djmcfar
                  New Member
                  • Jul 2020
                  • 1

                  #9
                  Thank you very much for your post hsriat, it's just what the doctor ordered! I know that it's years after the fact, but just wanted to say thanks :)

                  Comment

                  Working...