Results 1 to 7 of 7

Thread: [RESOLVED] Reverse Image

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Posts
    266

    Resolved [RESOLVED] Reverse Image

    Hi,
    Is it possible to reverse picture using PHP ? Please help me solve it out. I have a picture and I like to reverse the picture on the basis of some condition runtime from the PHP script.

    Thanks a lot in advance.

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Reverse Image

    Reverse how? Flip horizontally or vertically, or invert colours?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Posts
    266

    Smile Re: Reverse Image

    Reverse means 180 degree reverse.

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Reverse Image

    Rotate, you mean.

    There's a sample of exactly that on this page.
    http://php.about.com/od/gdlibrary/a/rotate_image_gd.htm

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Posts
    266

    Question Re: Reverse Image

    Thanks penagate. This code is working fine. But I faced trouble by use the code in the following manner.

    I am trying to use it as a function. I am getting error regarding header information. But I do not understand where I have done the mess. Please help me.

    PHP Code:

    <?php

    function Image_Rotate($path)
    {
        
    // The file you are rotating
        
    $temp="Test";
        
    $image=$path.".jpg";

        
    //How many degrees you wish to rotate
        
    $degrees 180;

        
    // This sets the image type to .jpg but can be changed to png or gif
        
    header('Content-type: image/jpeg') ;

        
    // Create the canvas
        
    $source imagecreatefromjpeg($image) ;

        
    // Rotates the image
        
    $rotate imagerotate($source$degrees0) ;

        
    // Outputs a jpg image, you could change this to gif or png if needed
        
    return imagejpeg($rotate) ;
    }

    ?>

    <html>
    <head>
    <title>Image Rotate</title>
    </head>
    <body>
    <form name="f" method="POST" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
    <table border="1" width="100%">
        <tr>
            <td width="50%" align="center">
                <?php
                        $temp
    ="Test";
                        
    $pic="pics/".strtolower($temp);
                        echo 
    "<img src='{$pic}.jpg' type='image'>";
                
    ?>
            </td>
            <td align="center">
                <?php
                        $temp
    ="Test";
                        
    $pic="pics/".strtolower($temp);
                        
    $pic=Image_Rotate($pic);
                        echo 
    "<img src='{$pic}.jpg' type='image'>";
                
    ?>
            </td>
        </tr>
    </table>
    </form>
    </body>
    </html>
    Thanks a lot again.

  6. #6
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Ubuntu Haters Club
    Posts
    405

    Re: Reverse Image

    You are sending content to the browser, THEN calling the function, you can't do that.

    That code wouldn't work anyway. You need to put it into a seperate page, and I would suggest that you make it operate off of $_GET.

    Here's an example (using your code so sorry if it doesn't work) of what I mean:
    PHP Code:
    <?php
    // image.php
    $image=$_GET['image']; 

    //How many degrees you wish to rotate 
    $degrees 180

    // This sets the image type to .jpg but can be changed to png or gif 
    header('Content-type: image/jpeg') ; 

    // Create the canvas 
    $source imagecreatefromjpeg($image) ; 

    // Rotates the image 
    $rotate imagerotate($source$degrees0) ; 

    // Outputs a jpg image, you could change this to gif or png if needed 
    imagejpeg($rotate);
    ?>
    PHP Code:
    <html> 
    <head> 
    <title>Image Rotate</title> 
    </head> 
    <body> 
    <form name="f" method="POST" action="<?php echo $_SERVER["PHP_SELF"]; ?>"> 
    <table border="1" width="100%"> 
        <tr> 
            <td width="50%" align="center"> 
                <img src="pics/whatever.jpg" alt="Non-rotated" />
            </td> 
            <td align="center"> 
                <img src="image.php?image=pics/whatever.jpg" alt="Rotated" />
            </td> 
        </tr> 
    </table> 
    </form> 
    </body> 
    </html>
    Should work.
    » Twitter: @rudi_visser : Website: www.rudiv.se «

    If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Posts
    266

    Thumbs up Re: Reverse Image

    Thanks a lot RudiVisser. This code is working fine.

Posting Permissions

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



Click Here to Expand Forum to Full Width