How to rotate an image?

Hi all,
I want to align 3 images in a row like;

http://www.onlinecables.com/rf-fxc/index.php3?conn1=01&conn2=00&cable=00&length=

based on the selection of 3 select boxes, the images are populated.
First the images are aligned properly…
and the connectors are same, but it rotates for each side…
I have the image, that fits on left-side.
Now i want to rotate the same image for right-side connection for the cable…

I am using 3 div tags, for 3 select box results.

Now the problem is,
I want to align and rotate the third image(ie right-end connector).

Give me some idea or example to do it.
Thanking you…

It sounds like you want to flip the image rather than rotate it.


/**
 * Flip (mirror) an image left to right.
 *
 * @param image  resource
 * @param x      int
 * @param y      int
 * @param width  int
 * @param height int
 * @return bool
 * @require PHP 3.0.7 (function_exists), GD1
 */
function imageflip(&$image, $x = 0, $y = 0, $width = null,
    $height = null)
{
    if ($width  < 1) $width  = imagesx($image);
    if ($height < 1) $height = imagesy($image);
    // Truecolor provides better results, if possible.
    if (function_exists('imageistruecolor') &&
        imageistruecolor($image))
    {
        $tmp = imagecreatetruecolor(1, $height);
    }
    else
    {
        $tmp = imagecreate(1, $height);
    }
    $x2 = $x + $width - 1;
    for ($i = (int)floor(($width - 1) / 2); $i >= 0; $i--)
    {
        // Backup right stripe.
        imagecopy($tmp,   $image, 0,        0,  $x2 - $i, $y,
            1, $height);
        // Copy left stripe to the right.
        imagecopy($image, $image, $x2 - $i, $y, $x + $i,  $y,
            1, $height);
        // Copy backuped right stripe to the left.
        imagecopy($image, $tmp,   $x + $i,  $y, 0,        0,
            1, $height);
    }
    imagedestroy($tmp);
    return true;
}

This popped up on my first search for '[URL=“http://www.google.co.uk/search?q=php+gd+flip+image”]php gd flip image’.

How to pass the image source…
I tried like this:::
$image=“43.gif”;

And i call the function.

but it shows warnings like;

Warning: imagesx() expects parameter 1 to be resource, string given

You can use the function definition to write your own which supports this, failing that, pass it an image resource.

I posted the function to point you in the right direction, you need to flip, not rotate. :slight_smile:

Like this i called that function:::

function imageflip(‘43.gif’, $x = 0, $y = 0, $width = null,$height = null);

But it is showing error like that;

Warning: imagesx() expects parameter 1 to be resource, string given

Why don’t you try to fix that error, it’s pretty explicit. Let me know if you need some help with your code. :slight_smile:

How to fix,
Dynamically i will generate the image name based on the selection of select box.
That is stored in a variable, and pass it to this method, but it is showing the warning message.

Then how to pass the image resource to this function?
In php, there is a function like image rotate…
But there also, same problem arise to me…

Give me the help regarding the code to do this…

thanking you…