View Full Version : Flip OR Flop an image
snyhof
06-29-2007, 11:01 PM
I am looking for a way (with PHP or JS) to flip (sometimes called flop) an image horizontally. Same image only flipped as a mirror reverse. I have house plans on my site and people like to view the plans reversed at times and I have never pulled that off.
Any ideas or script? I just want to click on the link to flip the image, then click the link again (or another one) to flip it back.
Thank you,
Steve Nyhof
thetestingsite
06-29-2007, 11:48 PM
You could make 2 images (one normal and one reversed), then use javascript to change the source of the image to the mirrored one and visa versa.
Hope this helps.
snyhof
06-29-2007, 11:55 PM
I have found the fliph() function. only works in IE, but thats ok. I have thousands of images. I am not going to make duplicates. I knew there was a function, I just didn't know what it was called. I have it working now with just on button, but have more work to do.
Thank you for your reply.
alexjewell
06-30-2007, 12:52 AM
So forget about non-IE users? Haha.
snyhof
06-30-2007, 12:58 AM
While I enjoy FF, most of my clients (builders) are IE users because they have learned where the start button is to the computer, and that the big blue E means - serf the web. So I am stuck with IE. Sometimes I go to their office and find the screen res at 640 x 480 because something reset.
I am also a builder so I can pick on them. The difference is that I have been monkeying with computers for over 17 years.
alexjewell
06-30-2007, 01:00 AM
Haha, I see.
djr33
06-30-2007, 02:40 AM
Can you just set a negative width on the images? I forget if this works or not.
You can use the PHP GD library to reverse them, but this would process each pixel and be a stress on your server.
snyhof
06-30-2007, 02:43 AM
I am interested in PHP because that's what my site is run on. I have looked into the flop function?? but cannot find enough info to help me. I am currently learning javascript and PHP through online courses, but I really need to figure this thing out.
I want to be able to flip a number of images (elevation and floor plans) inside a div or something like an id=
Any help?
djr33
06-30-2007, 03:22 AM
Here's an alternative image-flipping function which is simpler than either of the ones
I've seen in the docs here. It takes the source image and the mode (zero for horizontal,
nonzero for vertical) and returns the flipped image.
<?php
function imageflip($image, $mode) {
$w = imagesx($image);
$h = imagesy($image);
$flipped = imagecreate($w, $h);
if ($mode) {
for ($y = 0; $y < $h; $y++) {
imagecopy($flipped, $image, 0, $y, 0, $h - $y - 1, $w, 1);
}
} else {
for ($x = 0; $x < $w; $x++) {
imagecopy($flipped, $image, $x, 0, $w - $x - 1, 0, 1, $h);
}
}
return $flipped;
}
?>
From: http://www.php.net/imagecopy
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.