imagerotate problem with PHP 4.3.9 - PHP 5.2.0 using GD2

imagerotate problem with PHP 4.3.9 - PHP 5.2.0 using GD2

am 20.06.2007 15:45:03 von phillip.s.powell

Recap:

Using imagerotate within PHP 4.3.9 - PHP 5.2.0 for both XP and Linux,
all using GD2

If you rotate an image 180 degrees, all is fine

If you rotate an image > 0 degrees and < 180 degrees, or > 180 degrees
and < 360 degrees, while the image will rotate, its dimensions are
somehow not refactored and as a result you get a rather annoying black
bar in the newly-rotated image, along with part of your image being
cropped off.

I learned about a possible workaround with ImageMagick's convert
command, but has anyone found a better solution (other than using XP's
built-in image rotation routines)?

Thanks
Phil

Re: imagerotate problem with PHP 4.3.9 - PHP 5.2.0 using GD2

am 20.06.2007 16:02:27 von luiheidsgoeroe

On Wed, 20 Jun 2007 15:45:03 +0200, comp.lang.php
wrote:

> Recap:
>
> Using imagerotate within PHP 4.3.9 - PHP 5.2.0 for both XP and Linux,
> all using GD2
>
> If you rotate an image 180 degrees, all is fine
>
> If you rotate an image > 0 degrees and < 180 degrees, or > 180 degrees
> and < 360 degrees, while the image will rotate, its dimensions are
> somehow not refactored and as a result you get a rather annoying black
> bar in the newly-rotated image, along with part of your image being
> cropped off.
>
> I learned about a possible workaround with ImageMagick's convert
> command, but has anyone found a better solution (other than using XP's
> built-in image rotation routines)?

Depends on what you want from it, how would you like it to behave on
arbitrary angle? Calculate the width & height needed for the new image,
create that, set the backgroundcolor of your choice on it, and paste the
image in it & rotate.


--
Rik Wasmus

Re: imagerotate problem with PHP 4.3.9 - PHP 5.2.0 using GD2

am 20.06.2007 16:02:27 von luiheidsgoeroe

On Wed, 20 Jun 2007 15:45:03 +0200, comp.lang.php
wrote:

> Recap:
>
> Using imagerotate within PHP 4.3.9 - PHP 5.2.0 for both XP and Linux,
> all using GD2
>
> If you rotate an image 180 degrees, all is fine
>
> If you rotate an image > 0 degrees and < 180 degrees, or > 180 degrees
> and < 360 degrees, while the image will rotate, its dimensions are
> somehow not refactored and as a result you get a rather annoying black
> bar in the newly-rotated image, along with part of your image being
> cropped off.
>
> I learned about a possible workaround with ImageMagick's convert
> command, but has anyone found a better solution (other than using XP's
> built-in image rotation routines)?

Depends on what you want from it, how would you like it to behave on
arbitrary angle? Calculate the width & height needed for the new image,
create that, set the backgroundcolor of your choice on it, and paste the
image in it & rotate.


--
Rik Wasmus

Re: imagerotate problem with PHP 4.3.9 - PHP 5.2.0 using GD2

am 20.06.2007 16:32:03 von phillip.s.powell

On Jun 20, 10:02 am, Rik wrote:
> On Wed, 20 Jun 2007 15:45:03 +0200, comp.lang.php
>
>
>
>
>
> wrote:
> > Recap:
>
> > Using imagerotate within PHP 4.3.9 - PHP 5.2.0 for both XP and Linux,
> > all using GD2
>
> > If you rotate an image 180 degrees, all is fine
>
> > If you rotate an image > 0 degrees and < 180 degrees, or > 180 degrees
> > and < 360 degrees, while the image will rotate, its dimensions are
> > somehow not refactored and as a result you get a rather annoying black
> > bar in the newly-rotated image, along with part of your image being
> > cropped off.
>
> > I learned about a possible workaround with ImageMagick's convert
> > command, but has anyone found a better solution (other than using XP's
> > built-in image rotation routines)?
>
> Depends on what you want from it, how would you like it to behave on
> arbitrary angle? Calculate the width & height needed for the new image,
> create that, set the backgroundcolor of your choice on it, and paste the
> image in it & rotate.

I did that after imagerotate misbehaved the first time, however, it
seems as if imagerotate ignored the newly-calculated height and weight
options.

Say for instance you have an image of 300 x 150. If you rotate 90
degrees the image should be 150 x 300 with the image contents
perfectly rotated. Instead you have an image of 150 x 300 with a big
black bar on the right. This in spite of recalculating the correct
height and width for the new image.

>
> --
> Rik Wasmus- Hide quoted text -
>
> - Show quoted text -

Re: imagerotate problem with PHP 4.3.9 - PHP 5.2.0 using GD2

am 20.06.2007 16:32:03 von phillip.s.powell

On Jun 20, 10:02 am, Rik wrote:
> On Wed, 20 Jun 2007 15:45:03 +0200, comp.lang.php
>
>
>
>
>
> wrote:
> > Recap:
>
> > Using imagerotate within PHP 4.3.9 - PHP 5.2.0 for both XP and Linux,
> > all using GD2
>
> > If you rotate an image 180 degrees, all is fine
>
> > If you rotate an image > 0 degrees and < 180 degrees, or > 180 degrees
> > and < 360 degrees, while the image will rotate, its dimensions are
> > somehow not refactored and as a result you get a rather annoying black
> > bar in the newly-rotated image, along with part of your image being
> > cropped off.
>
> > I learned about a possible workaround with ImageMagick's convert
> > command, but has anyone found a better solution (other than using XP's
> > built-in image rotation routines)?
>
> Depends on what you want from it, how would you like it to behave on
> arbitrary angle? Calculate the width & height needed for the new image,
> create that, set the backgroundcolor of your choice on it, and paste the
> image in it & rotate.

I did that after imagerotate misbehaved the first time, however, it
seems as if imagerotate ignored the newly-calculated height and weight
options.

Say for instance you have an image of 300 x 150. If you rotate 90
degrees the image should be 150 x 300 with the image contents
perfectly rotated. Instead you have an image of 150 x 300 with a big
black bar on the right. This in spite of recalculating the correct
height and width for the new image.

>
> --
> Rik Wasmus- Hide quoted text -
>
> - Show quoted text -

Re: imagerotate problem with PHP 4.3.9 - PHP 5.2.0 using GD2

am 22.06.2007 15:18:51 von phillip.s.powell

Here is a visual example of what I mean.

Here is my original image:

http://valsignalandet.com/images/testshot.jpg

After I do this:


PHP Code:
if (!function_exists('imagerecreatetruecolor')) {
/**
* Recreate an existing image as a true color image {@link
http://us2.php.net/manual/en/function.imagerotate.php#62530 See notes
in imagerotate() for more information}
*
* @access public
* @param resource $image (reference)
* @return resource $image
*/
function &imagerecreatetruecolor(&$image) {
if (!imageistruecolor($image) &&
function_exists('imagecreatetruecolor')) {
list($width, $height) = array(@imagesx($image), @imagesy($image));
$tempImage = @imagecreatetruecolor($width, $height);
@imagecopy($tempImage, $image, 0, 0, 0, 0, $width, $height);
$image = $tempImage;
}
return $image;
}
}


/
*----------------------------------------------------------- -------------
------------------------------------------------------------ ---------------
Block to perform actions based upon checks. If you are to add text
you
will do a "imagefttext" function call;
if you are to add a border you will instantiate an
ImageBorderGenerator
class object; if you are to grayscale the
image you are to use the "imagecopymergegray" command ** and not
imagecopyresampled **
------------------------------------------------------------ --------------
------------------------------------------------------------ ---------------
*/
// NOTE THAT NEGATIVE NUMBERS GO CLOCKWISE IN imagerotate(), I PREFER
NEGATIVE GO COUNTERCLOCKWISE AND POSITIVE GO CLOCKWISE
if ($this->isSuccessful && $image && isset($angle) &&
is_numeric($angle))
$image = @imagerotate(imagerecreatetruecolor($image), -1 * $angle,
0); // ROTATE IMAGE



Here is your resulting image:

http://valsignalandet.com/images/testshot2.jpg

That might make it a bit more clear as far as what I mean by the
"black
bar".

On Jun 20, 10:32 am, "comp.lang.php"
wrote:
> On Jun 20, 10:02 am, Rik wrote:
>
>
>
>
>
> > On Wed, 20 Jun 2007 15:45:03 +0200, comp.lang.php
>
> > wrote:
> > > Recap:
>
> > > Using imagerotate within PHP 4.3.9 - PHP 5.2.0 for both XP and Linux,
> > > all using GD2
>
> > > If you rotate an image 180 degrees, all is fine
>
> > > If you rotate an image > 0 degrees and < 180 degrees, or > 180 degrees
> > > and < 360 degrees, while the image will rotate, its dimensions are
> > > somehow not refactored and as a result you get a rather annoying black
> > > bar in the newly-rotated image, along with part of your image being
> > > cropped off.
>
> > > I learned about a possible workaround with ImageMagick's convert
> > > command, but has anyone found a better solution (other than using XP's
> > > built-in image rotation routines)?
>
> > Depends on what you want from it, how would you like it to behave on
> > arbitrary angle? Calculate the width & height needed for the new image,
> > create that, set the backgroundcolor of your choice on it, and paste the
> > image in it & rotate.
>
> I did that after imagerotate misbehaved the first time, however, it
> seems as if imagerotate ignored the newly-calculated height and weight
> options.
>
> Say for instance you have an image of 300 x 150. If you rotate 90
> degrees the image should be 150 x 300 with the image contents
> perfectly rotated. Instead you have an image of 150 x 300 with a big
> black bar on the right. This in spite of recalculating the correct
> height and width for the new image.
>
>
>
>
>
> > --
> > Rik Wasmus- Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -- Hide quoted text -
>
> - Show quoted text -

Re: imagerotate problem with PHP 4.3.9 - PHP 5.2.0 using GD2

am 22.06.2007 15:18:51 von phillip.s.powell

Here is a visual example of what I mean.

Here is my original image:

http://valsignalandet.com/images/testshot.jpg

After I do this:


PHP Code:
if (!function_exists('imagerecreatetruecolor')) {
/**
* Recreate an existing image as a true color image {@link
http://us2.php.net/manual/en/function.imagerotate.php#62530 See notes
in imagerotate() for more information}
*
* @access public
* @param resource $image (reference)
* @return resource $image
*/
function &imagerecreatetruecolor(&$image) {
if (!imageistruecolor($image) &&
function_exists('imagecreatetruecolor')) {
list($width, $height) = array(@imagesx($image), @imagesy($image));
$tempImage = @imagecreatetruecolor($width, $height);
@imagecopy($tempImage, $image, 0, 0, 0, 0, $width, $height);
$image = $tempImage;
}
return $image;
}
}


/
*----------------------------------------------------------- -------------
------------------------------------------------------------ ---------------
Block to perform actions based upon checks. If you are to add text
you
will do a "imagefttext" function call;
if you are to add a border you will instantiate an
ImageBorderGenerator
class object; if you are to grayscale the
image you are to use the "imagecopymergegray" command ** and not
imagecopyresampled **
------------------------------------------------------------ --------------
------------------------------------------------------------ ---------------
*/
// NOTE THAT NEGATIVE NUMBERS GO CLOCKWISE IN imagerotate(), I PREFER
NEGATIVE GO COUNTERCLOCKWISE AND POSITIVE GO CLOCKWISE
if ($this->isSuccessful && $image && isset($angle) &&
is_numeric($angle))
$image = @imagerotate(imagerecreatetruecolor($image), -1 * $angle,
0); // ROTATE IMAGE



Here is your resulting image:

http://valsignalandet.com/images/testshot2.jpg

That might make it a bit more clear as far as what I mean by the
"black
bar".

On Jun 20, 10:32 am, "comp.lang.php"
wrote:
> On Jun 20, 10:02 am, Rik wrote:
>
>
>
>
>
> > On Wed, 20 Jun 2007 15:45:03 +0200, comp.lang.php
>
> > wrote:
> > > Recap:
>
> > > Using imagerotate within PHP 4.3.9 - PHP 5.2.0 for both XP and Linux,
> > > all using GD2
>
> > > If you rotate an image 180 degrees, all is fine
>
> > > If you rotate an image > 0 degrees and < 180 degrees, or > 180 degrees
> > > and < 360 degrees, while the image will rotate, its dimensions are
> > > somehow not refactored and as a result you get a rather annoying black
> > > bar in the newly-rotated image, along with part of your image being
> > > cropped off.
>
> > > I learned about a possible workaround with ImageMagick's convert
> > > command, but has anyone found a better solution (other than using XP's
> > > built-in image rotation routines)?
>
> > Depends on what you want from it, how would you like it to behave on
> > arbitrary angle? Calculate the width & height needed for the new image,
> > create that, set the backgroundcolor of your choice on it, and paste the
> > image in it & rotate.
>
> I did that after imagerotate misbehaved the first time, however, it
> seems as if imagerotate ignored the newly-calculated height and weight
> options.
>
> Say for instance you have an image of 300 x 150. If you rotate 90
> degrees the image should be 150 x 300 with the image contents
> perfectly rotated. Instead you have an image of 150 x 300 with a big
> black bar on the right. This in spite of recalculating the correct
> height and width for the new image.
>
>
>
>
>
> > --
> > Rik Wasmus- Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -- Hide quoted text -
>
> - Show quoted text -

Re: imagerotate problem with PHP 4.3.9 - PHP 5.2.0 using GD2

am 23.06.2007 17:36:21 von phillip.s.powell

GOT IT!!!

if (!function_exists('imagerecreatetruecolor')) {
/**
* Recreate an existing image as a true color image {@link
http://us2.php.net/manual/en/function.imagerotate.php#62530 See notes
in imagerotate() for more information}
*
* @access public
* @param resource $image (reference)
* @param boolean $willRotate (default false)
* @param int $angle (default 0)
* @return resource $image
*/
function &imagerecreatetruecolor(&$image, $willRotate = false, $angle
= 0) {
if (!imageistruecolor($image) &&
function_exists('imagecreatetruecolor')) {
if ($willRotate && (($angle > 0 && $angle < 180) || ($angle >
180 && $angle < 360))) {
list($width, $height) = array(@imagesy($image), @imagesx($image));
} else {
list($width, $height) = array(@imagesx($image), @imagesy($image));
}
$tempImage = @imagecreatetruecolor($width, $height);
@imagecopy($tempImage, $image, 0, 0, 0, 0, $width, $height);
$image = $tempImage;
}
return $image;
}
}

// NOTE THAT NEGATIVE NUMBERS GO CLOCKWISE IN imagerotate(), I PREFER
NEGATIVE GO COUNTERCLOCKWISE AND POSITIVE GO CLOCKWISE
if ($this->isSuccessful && $image && isset($angle) &&
is_numeric($angle)) $newImage = $image =
@imagerotate(imagerecreatetruecolor($image, 'willRotate', $angle), -1
* $angle, 0); // ROTATE IMAGE



On Jun 20, 9:45 am, "comp.lang.php"
wrote:
> Recap:
>
> Using imagerotate within PHP 4.3.9 - PHP 5.2.0 for both XP and Linux,
> all using GD2
>
> If you rotate an image 180 degrees, all is fine
>
> If you rotate an image > 0 degrees and < 180 degrees, or > 180 degrees
> and < 360 degrees, while the image will rotate, its dimensions are
> somehow not refactored and as a result you get a rather annoying black
> bar in the newly-rotated image, along with part of your image being
> cropped off.
>
> I learned about a possible workaround with ImageMagick's convert
> command, but has anyone found a better solution (other than using XP's
> built-in image rotation routines)?
>
> Thanks
> Phil

Re: imagerotate problem with PHP 4.3.9 - PHP 5.2.0 using GD2

am 23.06.2007 17:36:21 von phillip.s.powell

GOT IT!!!

if (!function_exists('imagerecreatetruecolor')) {
/**
* Recreate an existing image as a true color image {@link
http://us2.php.net/manual/en/function.imagerotate.php#62530 See notes
in imagerotate() for more information}
*
* @access public
* @param resource $image (reference)
* @param boolean $willRotate (default false)
* @param int $angle (default 0)
* @return resource $image
*/
function &imagerecreatetruecolor(&$image, $willRotate = false, $angle
= 0) {
if (!imageistruecolor($image) &&
function_exists('imagecreatetruecolor')) {
if ($willRotate && (($angle > 0 && $angle < 180) || ($angle >
180 && $angle < 360))) {
list($width, $height) = array(@imagesy($image), @imagesx($image));
} else {
list($width, $height) = array(@imagesx($image), @imagesy($image));
}
$tempImage = @imagecreatetruecolor($width, $height);
@imagecopy($tempImage, $image, 0, 0, 0, 0, $width, $height);
$image = $tempImage;
}
return $image;
}
}

// NOTE THAT NEGATIVE NUMBERS GO CLOCKWISE IN imagerotate(), I PREFER
NEGATIVE GO COUNTERCLOCKWISE AND POSITIVE GO CLOCKWISE
if ($this->isSuccessful && $image && isset($angle) &&
is_numeric($angle)) $newImage = $image =
@imagerotate(imagerecreatetruecolor($image, 'willRotate', $angle), -1
* $angle, 0); // ROTATE IMAGE



On Jun 20, 9:45 am, "comp.lang.php"
wrote:
> Recap:
>
> Using imagerotate within PHP 4.3.9 - PHP 5.2.0 for both XP and Linux,
> all using GD2
>
> If you rotate an image 180 degrees, all is fine
>
> If you rotate an image > 0 degrees and < 180 degrees, or > 180 degrees
> and < 360 degrees, while the image will rotate, its dimensions are
> somehow not refactored and as a result you get a rather annoying black
> bar in the newly-rotated image, along with part of your image being
> cropped off.
>
> I learned about a possible workaround with ImageMagick's convert
> command, but has anyone found a better solution (other than using XP's
> built-in image rotation routines)?
>
> Thanks
> Phil