Imagick question

Imagick question

am 05.11.2009 09:48:51 von Ashley

I'm trying to use Imagick:roundCorners() however the resulting image
has the background color on the corners set to black if I save the image
as a JPG format. If I save it as a PNG format, the rounded corners are
transparent. Does anyone know if the background color can be set to
white when saving as a JPG format? I'd rather have 122K over 371K for a
file size ...

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Imagick question

am 05.11.2009 10:46:13 von Brady Mitchell

On Thu, Nov 5, 2009 at 12:48 AM, Ashley M. Kirchner wro=
te:
> =A0 I'm trying to use Imagick:roundCorners() however the resulting image =
has
> the background color on the corners set to black if I save the image as a
> JPG format. =A0If I save it as a PNG format, the rounded corners are
> transparent. =A0Does anyone know if the background color can be set to wh=
ite
> when saving as a JPG format? =A0I'd rather have 122K over 371K for a file=
size

I'm sure it can be done, but without seeing your code we can't really help.

Brady

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Imagick question

am 05.11.2009 12:15:39 von Ashley Sheridan

--=-oRZ/5/4tmYSBF4KrXnCF
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

On Thu, 2009-11-05 at 01:46 -0800, Brady Mitchell wrote:

> On Thu, Nov 5, 2009 at 12:48 AM, Ashley M. Kirchner wrote:
> > I'm trying to use Imagick:roundCorners() however the resulting image has
> > the background color on the corners set to black if I save the image as a
> > JPG format. If I save it as a PNG format, the rounded corners are
> > transparent. Does anyone know if the background color can be set to white
> > when saving as a JPG format? I'd rather have 122K over 371K for a file size
>
> I'm sure it can be done, but without seeing your code we can't really help.
>
> Brady
>


It might be that you need to define white as a first colour first and
fill the canvas with it. I've had similar problems in GD which were
solved like this.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--=-oRZ/5/4tmYSBF4KrXnCF--

Re: Imagick question

am 05.11.2009 20:22:51 von Ashley

Brady Mitchell wrote:
> I'm sure it can be done, but without seeing your code we can't really
> help.
Easily solved. From the PHP manual
(http://www.php.net/manual/en/function.imagick-roundcorners. php):


$image = new Imagick();
$image->newPseudoImage(100, 100, "magick:rose");
$image->setImageFormat("png");

$image->roundCorners(5,3);
$image->writeImage("rounded.png");
?>

That produces a nice transparent cornered image, as it should.
However, try saving it as a JEPG instead. Set the image format to
'jpeg' and write it out as 'rounded.jpg' and you'll notice the corners
are now black.

I know JPEG doesn't support transparency, that's fine. What I want
is to change the black to white instead.

-- A

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Imagick question

am 05.11.2009 21:08:57 von Ashley Sheridan

--=-exmXSZTv+d17r1fxj061
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

On Thu, 2009-11-05 at 12:22 -0700, Ashley M. Kirchner wrote:

> Brady Mitchell wrote:
> > I'm sure it can be done, but without seeing your code we can't really
> > help.
> Easily solved. From the PHP manual
> (http://www.php.net/manual/en/function.imagick-roundcorners. php):
>
> >
> $image = new Imagick();
> $image->newPseudoImage(100, 100, "magick:rose");
> $image->setImageFormat("png");
>
> $image->roundCorners(5,3);
> $image->writeImage("rounded.png");
> ?>
>
> That produces a nice transparent cornered image, as it should.
> However, try saving it as a JEPG instead. Set the image format to
> 'jpeg' and write it out as 'rounded.jpg' and you'll notice the corners
> are now black.
>
> I know JPEG doesn't support transparency, that's fine. What I want
> is to change the black to white instead.
>
> -- A
>


Fill the background with white before you create the corners.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--=-exmXSZTv+d17r1fxj061--

Re: Imagick question

am 05.11.2009 21:23:32 von Ashley

Ashley Sheridan wrote:
> Fill the background with white before you create the corners.
Well, I tried that, with no luck. This is my actual code:

$width = 150;
$height = 150;
$im = new Imagick('original/' . $filename);
$im->thumbnailImage($width, $height, true);
$im->sharpenImage(50, 1);
$im->setImageBackgroundColor('white');
$im->roundCorners(5, 5, 7);
$im->setImageFormat('jpeg');
$im->writeImage('thumbnail/' . $filename);
$im->clear();
$im->destroy();

--
H | It's not a bug - it's an undocumented feature.
+----------------------------------------------------------- ---------
Ashley M. Kirchner . 303.442.6410 x130
IT Director / SysAdmin . 800.441.3873 x130
Photo Craft Imaging . 2901 55th Street
http://www.pcraft.com ..... . . . Boulder, CO 80301, U.S.A.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Imagick question

am 06.11.2009 21:32:37 von Jason Young

I think to do this effectively, you'll need to create two images, as
such (adapting from your code):

$width = 150;
$height = 150;
$background = 'white';

$im = new Imagick();
$im->newImage($width, $height, $background);

$thumb = new Imagick('original/' . $filename);
$thumb->thumbnailImage($width, $height, true);
$thumb->sharpenImage(50, 1);
$thumb->roundCorners(5, 5, 7);

$im->compositeImage($thumb, Imagick::COMPOSITE_OVER, 0, 0);
$im->setImageFormat('jpeg');
$im->flattenImages();

$im->writeImage('thumbnail/' . $filename);
/* Or display directly to screen
header("Content-Type: image/jpeg");
echo $im;
*/
$im->clear();
$im->destroy();
$cv->clear();
$cv->destroy();
?>

That seems to be the only way I can find to control which colors are used.

-Jason

Ashley M. Kirchner wrote:
> Ashley Sheridan wrote:
>> Fill the background with white before you create the corners.
> Well, I tried that, with no luck. This is my actual code:
>
> $width = 150;
> $height = 150;
> $im = new Imagick('original/' . $filename);
> $im->thumbnailImage($width, $height, true);
> $im->sharpenImage(50, 1);
> $im->setImageBackgroundColor('white');
> $im->roundCorners(5, 5, 7);
> $im->setImageFormat('jpeg');
> $im->writeImage('thumbnail/' . $filename);
> $im->clear();
> $im->destroy();
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php