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
https://forums.phpfreaks.com/topic/98113-php-flip-image/
Share on other sites

Different MODE results

[pre]

                          O                                            O

                          \                                          / 

    original              \                      HORIZONTAL        / 

                            X                                      X   

                               

                            X 

    VERTICAL              / 

                          /   

                          O   

 

Link to comment
https://forums.phpfreaks.com/topic/98113-php-flip-image/#findComment-501950
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
https://forums.phpfreaks.com/topic/98113-php-flip-image/#findComment-502903
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.