Jump to content

PHP Flip Image


The14thGOD

Recommended Posts

I'm trying to figure out how to make this function work, I'm not as familiar with functions and this function doesn't seem to have anything more to explain it. I found it here:

http://www.php.net/manual/en/ref.image.php#62029

<?php
// This is a correction to the image-flipping function I posted previously.
// The bitwise ands (&) were incorrectly written as logical ands (&&).
// Needless to say, that breaks the function in obnoxious--if amusing--ways.

define("VERTICAL", 1);
define("HORIZONTAL", 2);

function imageflip($image, $mode) {
       $w = imagesx($image);
       $h = imagesy($image);
       $flipped = imagecreate($w, $h);
       if ($mode & VERTICAL) {
               for ($y = 0; $y < $h; $y++) {
                       imagecopy($flipped, $image , 0, $y, 0, $h - $y - 1, $w, 1);
               }
       }
       if ($mode & HORIZONTAL) {
               for ($x = 0; $x < $w; $x++) {
                       imagecopy($flipped, $image , $x, 0, $w - $x - 1, 0, 1, $h);
               }
       }
       return $flipped;
}
?>

I've called the function before and put the image location into where image is but I'm confused on the mode.

Anyone familiar with this?

Any help would be great, thanks in advance.

 

Justin

Link to comment
Share on other sites

Different MODE results

[pre]

                          O                                            O

                          \                                          / 

    original              \                      HORIZONTAL        / 

                            X                                      X   

                               

                            X 

    VERTICAL              / 

                          /   

                          O   

 

Link to comment
Share on other sites

Alright, that clears up some of it, like I said I'm new to functions and I appreciate the help.

 

I've run into a problem displaying the image, here's some examples of what I've tried

 

<?php include("includes/flip_image.php"); 
			$image = "images/sideimgs/side02.jpg";
			imageflip("images/sideimgs/side02.jpg",HORIZONTAL);
//imageflip($image,HORIZONTAL);
		?>
		<img class="rightimg" src="<?= $flipped ?>" width="154" height="768" alt="Side Image" />

 

I've also tried putting 1 line into where the $flipped is, so $flipped = imageflip($image,HORIZONTAL).

 

Nothing shows up in the code when i look at the source, it looks like src="".

Again, ty for the help.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.