Background issue converting .eps to .png

View: New views
11 Messages — Rating Filter:   Alert me  

Background issue converting .eps to .png

by Michael Stroh-2 :: Rate this Message:

| View Threaded | Show Only this Message

Hello. I'm trying to convert some graphs I have saved as .eps to .png  
files. When I run convert version 6.3.3 on my laptop, it performs the  
conversions just fine. However, my desktop at work uses 6.4.4 and when  
I try to do the conversion on it, it seems to handle the background of  
the images incorrectly (both are Macs). I'm not sure if it is treating  
the background as a transparency or what the issue is.

As an example, I have an image posted (www.astroh.org/image_test/lightcurve.png)
  which shows how the conversion ends up on my desktop. However, I am  
able to perform the conversions from .eps to .jpg fine (www.astroh.org/image_test/lightcurve.jpg)
  but the quality is terrible. The .eps file that I'm converting from  
can also be found in the same folder as the other two images (www.astroh.org/image_test/lightcurve.eps)
.

I'm using simple commands like

convert lightcurve.eps lightcurve.png

Are there any additional things I can try to get the .png file to look  
the way I want it to?

Cheers,
Michael Stroh
_______________________________________________
Magick-users mailing list
Magick-users@...
http://studio.imagemagick.org/mailman/listinfo/magick-users

Re: Background issue converting .eps to .png

by zentara-2 :: Rate this Message:

| View Threaded | Show Only this Message

On Tue, 21 Oct 2008 12:43:05 -0400
Michael Stroh <stroh@...> wrote:

>I'm using simple commands like
>
>convert lightcurve.eps lightcurve.png
>
>Are there any additional things I can try to get the .png file to look  
>the way I want it to?
>
>Cheers,
>Michael Stroh
Yeah I saw the lossy looking output too, with IM-6.4.3, and the png had
a black frame.

This 2 step convert, first to pdf, then to png seems to give clear output.

convert -quality 100% -compress Lossless lightcurve.eps lightcurve1.pdf
convert -quality 100% -compress Lossless lightcurve1.pdf lightcurve1.png


There is some centering issue that needs to be worked out, but I'll leave
that for you. :-)  I seems the conversion to pdf rotates it into portrait mode,
without adjusting the dimensions.

zentara



--
I'm not really a human, but I play one on earth.
http://zentara.net/Remember_How_Lucky_You_Are.html 
_______________________________________________
Magick-users mailing list
Magick-users@...
http://studio.imagemagick.org/mailman/listinfo/magick-users

Re: Background issue converting .eps to .png

by zentara-2 :: Rate this Message:

| View Threaded | Show Only this Message

On Tue, 21 Oct 2008 16:09:06 -0400
zentara <zentara1@...> wrote:

>On Tue, 21 Oct 2008 12:43:05 -0400
>Michael Stroh <stroh@...> wrote:
>
>>I'm using simple commands like
>>
>>convert lightcurve.eps lightcurve.png
>>
>>Are there any additional things I can try to get the .png file to look  
>>the way I want it to?
>>
>>Cheers,
>>Michael Stroh
>Yeah I saw the lossy looking output too, with IM-6.4.3, and the png had
>a black frame.
>
>This 2 step convert, first to pdf, then to png seems to give clear output.
>
>convert -quality 100% -compress Lossless lightcurve.eps lightcurve1.pdf
>convert -quality 100% -compress Lossless lightcurve1.pdf lightcurve1.png
>
>
>There is some centering issue that needs to be worked out, but I'll leave
>that for you. :-)  I seems the conversion to pdf rotates it into portrait mode,
>without adjusting the dimensions.
>
>zentara

Hi, a few more minutes of hacking, and I found trim.
This may not be the best way, but it makes a nice png.
The resize 99% seems to auto convert it to landscape.

######################
convert -resize 99% -density 160x160 -quality 100% -compress Lossless lightcurve.eps lightcurve1.pdf

convert -quality 100% -compress Lossless lightcurve1.pdf lightcurve1.png

convert lightcurve1.png -trim lightcurve2.png
######################

I'm sure there is some code condensation needed, but it works. :-)  

zentara

--
I'm not really a human, but I play one on earth.
http://zentara.net/Remember_How_Lucky_You_Are.html 
_______________________________________________
Magick-users mailing list
Magick-users@...
http://studio.imagemagick.org/mailman/listinfo/magick-users

Re: Background issue converting .eps to .png

by zentara-2 :: Rate this Message:

| View Threaded | Show Only this Message

On Tue, 21 Oct 2008 12:43:05 -0400
Michael Stroh <stroh@...> wrote:


>I'm using simple commands like
>
>convert lightcurve.eps lightcurve.png
>
>Are there any additional things I can try to get the .png file to look  
>the way I want it to?

Here is a Perl script that does the conversion, and avoids a temp pdf file
by using a blob.

#!/usr/bin/perl
use warnings;
use strict;
use Image::Magick;

# a shell script equivalent... for comparison
#convert -resize 99% -density 160x160 -quality 100% -compress Lossless lightcurve.eps lightcurve1.pdf
#convert -quality 100% -compress Lossless lightcurve1.pdf lightcurve1.png
#convert lightcurve1.png -trim lightcurve2.png
#convert -bordercolor SkyBlue -border 40x40 lightcurve2.png  lightcurve3.png

my $img = Image::Magick->new;
$img->Read('lightcurve.eps');
$img->Resize('101%');  #needed hack for portrait/landscape conversion
$img->set('quality'=> 100, );
$img->set('compresion'=> 'LosslessJPEG' );
#$img->Write(filename=>'zzimage.pdf'); #works good when written to temp file
# but using an inline blob here to avoid a temp file
$img->set('magick'=>'pdf');
my $blob = $img->ImageToBlob();

#and the opposite
my $img1 = Image::Magick->new(magick=>'pdf');
$img1->BlobToImage( $blob );
$img1->set('quality'=> 100, );
$img1->set('compresion'=> 'LosslessJPEG' );

#add a border
$img1->Border('bordercolor' => 'SkyBlue','width'=>40,'height'=>40);

$img1->Write(filename=>'zzzimage.jpg');
$img1->Write(filename=>'zzzimage.png');

__END__


zentara

--
I'm not really a human, but I play one on earth.
http://zentara.net/Remember_How_Lucky_You_Are.html 
_______________________________________________
Magick-users mailing list
Magick-users@...
http://studio.imagemagick.org/mailman/listinfo/magick-users

Re: Background issue converting .eps to .png

by Anthony Thyssen :: Rate this Message:

| View Threaded | Show Only this Message

zentara on  wrote...
| On Tue, 21 Oct 2008 12:43:05 -0400
| Michael Stroh <stroh@...> wrote:
|
| >I'm using simple commands like
| >
| >convert lightcurve.eps lightcurve.png
| >
| >Are there any additional things I can try to get the .png file to look  
| >the way I want it to?
| >
| >Cheers,
| >Michael Stroh
| Yeah I saw the lossy looking output too, with IM-6.4.3, and the png had
| a black frame.
|
| This 2 step convert, first to pdf, then to png seems to give clear output.
|
| convert -quality 100% -compress Lossless lightcurve.eps lightcurve1.pdf
| convert -quality 100% -compress Lossless lightcurve1.pdf lightcurve1.png
|
|
| There is some centering issue that needs to be worked out, but I'll leave
| that for you. :-)  I seems the conversion to pdf rotates it into portrait mode,
| without adjusting the dimensions.
|
|
| Using -trim
|
| This may not be the best way, but it makes a nice png.
| The resize 99% seems to auto convert it to landscape.
|
| ######################
| convert -resize 99% -density 160x160 -quality 100% -compress Lossless lightcurve.eps lightcurve1.pdf
|
| convert -quality 100% -compress Lossless lightcurve1.pdf lightcurve1.png
|
| convert lightcurve1.png -trim lightcurve2.png
| ######################
|
| I'm sure there is some code condensation needed, but it works. :-)  
| zentara
|

I would really suggets you read in images before resizing them!
that is do the operations in order.

As such the first line becomes...

  convert -density 160x160  lightcurve.eps   -resize 99%  \
          -quality 100% -compress Lossles  lightcurve1.pdf

However removing the -resize from the above as you were previously doing
maybe causing the 'delegate/coder handling' aspect of IM, see
   http://www.imagemagick.org/Usage/files/#delegates
to completely bypass the rasterization of the image.

You may be able get the equivelent result WITHOUT resizing by using
-taint.

Try this instead...

   convert -density 160x160  lightcurve.eps -taint \
           -quality 100% -compress Lossles  lightcurve1.pdf


  Anthony Thyssen ( System Programmer )    <A.Thyssen@...>
 -----------------------------------------------------------------------------
           "   ``   '   `   "   `'    ""    (Random Quotes)
 -----------------------------------------------------------------------------
     Anthony's Home is his Castle     http://www.cit.gu.edu.au/~anthony/
_______________________________________________
Magick-users mailing list
Magick-users@...
http://studio.imagemagick.org/mailman/listinfo/magick-users

Re: Background issue converting .eps to .png

by Anthony Thyssen :: Rate this Message:

| View Threaded | Show Only this Message

zentara on  wrote...
| On Tue, 21 Oct 2008 12:43:05 -0400
| Michael Stroh <stroh@...> wrote:
|
|
| >I'm using simple commands like
| >
| >convert lightcurve.eps lightcurve.png
| >
| >Are there any additional things I can try to get the .png file to look  
| >the way I want it to?
|
| Here is a Perl script that does the conversion, and avoids a temp pdf file
| by using a blob.
|
| #!/usr/bin/perl
| use warnings;
| use strict;
| use Image::Magick;
|
| # a shell script equivalent... for comparison
| #convert -resize 99% -density 160x160 -quality 100% -compress Lossless lightcurve.eps lightcurve1.pdf
| #convert -quality 100% -compress Lossless lightcurve1.pdf lightcurve1.png
| #convert lightcurve1.png -trim lightcurve2.png
| #convert -bordercolor SkyBlue -border 40x40 lightcurve2.png  lightcurve3.png
|
| my $img = Image::Magick->new;
| $img->Read('lightcurve.eps');
| $img->Resize('101%');  #needed hack for portrait/landscape conversion
| $img->set('quality'=> 100, );
| $img->set('compresion'=> 'LosslessJPEG' );
| #$img->Write(filename=>'zzimage.pdf'); #works good when written to temp file
| # but using an inline blob here to avoid a temp file
| $img->set('magick'=>'pdf');
| my $blob = $img->ImageToBlob();
|
| #and the opposite
| my $img1 = Image::Magick->new(magick=>'pdf');
| $img1->BlobToImage( $blob );
| $img1->set('quality'=> 100, );
| $img1->set('compresion'=> 'LosslessJPEG' );
|
| #add a border
| $img1->Border('bordercolor' => 'SkyBlue','width'=>40,'height'=>40);
|
| $img1->Write(filename=>'zzzimage.jpg');
| $img1->Write(filename=>'zzzimage.png');
|
| __END__
|
|
| zentara
|
| --
| I'm not really a human, but I play one on earth.
| http://zentara.net/Remember_How_Lucky_You_Are.html 
| _______________________________________________
| Magick-users mailing list
| Magick-users@...
| http://studio.imagemagick.org/mailman/listinfo/magick-users
  Anthony Thyssen ( System Programmer )    <A.Thyssen@...>
 -----------------------------------------------------------------------------
       :-)  Happy           :-D  Laughing Happy   :^)  Nosey
       :-(  Sad             :->  Sarcastic        :-O  Oh Wow!    
       :-|  Neutral Hmmm    ;-)  Wink, Joking     8-O  Oh My God!
              Smileys  --  Ascii Art for emotional effects
 -----------------------------------------------------------------------------
     Anthony's Home is his Castle     http://www.cit.gu.edu.au/~anthony/
_______________________________________________
Magick-users mailing list
Magick-users@...
http://studio.imagemagick.org/mailman/listinfo/magick-users

Re: Background issue converting .eps to .png

by Anthony Thyssen :: Rate this Message:

| View Threaded | Show Only this Message

zentara on  wrote...
| On Tue, 21 Oct 2008 12:43:05 -0400
| Michael Stroh <stroh@...> wrote:
|
|
| >I'm using simple commands like
| >
| >convert lightcurve.eps lightcurve.png
| >
| >Are there any additional things I can try to get the .png file to look  
| >the way I want it to?
|
| Here is a Perl script that does the conversion, and avoids a temp pdf file
| by using a blob.
|
| #!/usr/bin/perl
| use warnings;
| use strict;
| use Image::Magick;
|
| # a shell script equivalent... for comparison
| #convert -resize 99% -density 160x160 -quality 100% -compress Lossless lightcurve.eps lightcurve1.pdf
| #convert -quality 100% -compress Lossless lightcurve1.pdf lightcurve1.png
| #convert lightcurve1.png -trim lightcurve2.png
| #convert -bordercolor SkyBlue -border 40x40 lightcurve2.png  lightcurve3.png
|
| my $img = Image::Magick->new;
| $img->Read('lightcurve.eps');
| $img->Resize('101%');  #needed hack for portrait/landscape conversion
| $img->set('quality'=> 100, );
| $img->set('compresion'=> 'LosslessJPEG' );
| #$img->Write(filename=>'zzimage.pdf'); #works good when written to temp file
| # but using an inline blob here to avoid a temp file
| $img->set('magick'=>'pdf');
| my $blob = $img->ImageToBlob();
|
| #and the opposite
| my $img1 = Image::Magick->new(magick=>'pdf');
| $img1->BlobToImage( $blob );
| $img1->set('quality'=> 100, );
| $img1->set('compresion'=> 'LosslessJPEG' );
|
| #add a border
| $img1->Border('bordercolor' => 'SkyBlue','width'=>40,'height'=>40);
|
| $img1->Write(filename=>'zzzimage.jpg');
| $img1->Write(filename=>'zzzimage.png');
|
| __END__
|
Have you actually tried the super-sampling method...

  convert  -density 288  lightcurve.eps  -resize 25%  lightcurve.png


  Anthony Thyssen ( System Programmer )    <A.Thyssen@...>
 -----------------------------------------------------------------------------
                   A /  \  o       `` Impressive...
                  /</    \/|>         Obi Wan has taught you well. ''
                 / \       /\
                /___\      \ \                           -- StarWars
 -----------------------------------------------------------------------------
     Anthony's Home is his Castle     http://www.cit.gu.edu.au/~anthony/
_______________________________________________
Magick-users mailing list
Magick-users@...
http://studio.imagemagick.org/mailman/listinfo/magick-users

Re: Background issue converting .eps to .png

by zentara-2 :: Rate this Message:

| View Threaded | Show Only this Message

On Thu, 23 Oct 2008 10:35:16 +1000
Anthony Thyssen <anthony@...> wrote:

>zentara on  wrote...
>|
>| Here is a Perl script that does the conversion, and avoids a temp pdf file
>| by using a blob.


>Have you actually tried the super-sampling method...
>
>  convert  -density 288  lightcurve.eps  -resize 25%  lightcurve.png
>
>  Anthony Thyssen ( System Programmer )    <A.Thyssen@...>

That still results in a blacked-out png, only the red lines are visible, with
my IM-6.4.3

zentara

--
I'm not really a human, but I play one on earth.
http://zentara.net/Remember_How_Lucky_You_Are.html 
_______________________________________________
Magick-users mailing list
Magick-users@...
http://studio.imagemagick.org/mailman/listinfo/magick-users

Re: Background issue converting .eps to .png

by zentara-2 :: Rate this Message:

| View Threaded | Show Only this Message

On Thu, 23 Oct 2008 10:25:50 +1000
Anthony Thyssen <anthony@...> wrote:

>I would really suggets you read in images before resizing them!
>that is do the operations in order.
>
>As such the first line becomes...
>
>  convert -density 160x160  lightcurve.eps   -resize 99%  \
>          -quality 100% -compress Lossles  lightcurve1.pdf
>
>However removing the -resize from the above as you were previously doing
>maybe causing the 'delegate/coder handling' aspect of IM, see
>   http://www.imagemagick.org/Usage/files/#delegates
>to completely bypass the rasterization of the image.
>
>You may be able get the equivelent result WITHOUT resizing by using
>-taint.
>
>Try this instead...
>
>   convert -density 160x160  lightcurve.eps -taint \
>           -quality 100% -compress Lossles  lightcurve1.pdf
>

Yes, taint seems to work (I don't know why :-) )

The real questions seem to be:
1. Why does it need an intermediate convert to pdf to get clean fonts and a white background?
2. Why does a direct convert to png or jpg result in a black image?

IM is very powerful but can get complicated at times. :-)

zentara


--
I'm not really a human, but I play one on earth.
http://zentara.net/Remember_How_Lucky_You_Are.html 
_______________________________________________
Magick-users mailing list
Magick-users@...
http://studio.imagemagick.org/mailman/listinfo/magick-users

Re: Background issue converting .eps to .png

by Anthony Thyssen :: Rate this Message:

| View Threaded | Show Only this Message

zentara on  wrote...
| On Thu, 23 Oct 2008 10:25:50 +1000
| Anthony Thyssen <anthony@...> wrote:
|
| >I would really suggets you read in images before resizing them!
| >that is do the operations in order.
| >
| >As such the first line becomes...
| >
| >  convert -density 160x160  lightcurve.eps   -resize 99%  \
| >          -quality 100% -compress Lossles  lightcurve1.pdf
| >
| >However removing the -resize from the above as you were previously doing
| >maybe causing the 'delegate/coder handling' aspect of IM, see
| >   http://www.imagemagick.org/Usage/files/#delegates
| >to completely bypass the rasterization of the image.
| >
| >You may be able get the equivelent result WITHOUT resizing by using
| >-taint.
| >
| >Try this instead...
| >
| >   convert -density 160x160  lightcurve.eps -taint \
| >           -quality 100% -compress Lossles  lightcurve1.pdf
| >
|
| Yes, taint seems to work (I don't know why :-) )
|
| The real questions seem to be:
| 1. Why does it need an intermediate convert to pdf to get clean fonts and a white background?
| 2. Why does a direct convert to png or jpg result in a black image?
|
| IM is very powerful but can get complicated at times. :-)
|
Without the -taint  IM will call external programs (ghostscript) to
just directly convert EPS -> PDF, without actually reading (and
rasterizing) the image in memory.

See the IM examples delegates link above.

That means you are actually going

   EPS ->  raster  ->  PDF  -> raster  -> PNG

Which is VERY strange way of doing things.


  Anthony Thyssen ( System Programmer )    <A.Thyssen@...>
 -----------------------------------------------------------------------------
   Voice of the Resistance...
       I just wanted to mention for those who have asked, that
       absolutely nothing whatsoever happened today in sector 83x9x12
       I repeat nothing happened, please remain calm.          -- Babylon 5
 -----------------------------------------------------------------------------
     Anthony's Home is his Castle     http://www.cit.gu.edu.au/~anthony/
_______________________________________________
Magick-users mailing list
Magick-users@...
http://studio.imagemagick.org/mailman/listinfo/magick-users

Re: Background issue converting .eps to .png

by zentara-2 :: Rate this Message:

| View Threaded | Show Only this Message

On Tue, 21 Oct 2008 12:43:05 -0400
Michael Stroh <stroh@...> wrote:

>As an example, I have an image posted (www.astroh.org/image_test/lightcurve.png)
>  which shows how the conversion ends up on my desktop. However, I am  
>able to perform the conversions from .eps to .jpg fine (www.astroh.org/image_test/lightcurve.jpg)
>  but the quality is terrible. The .eps file that I'm converting from  
>can also be found in the same folder as the other two images (www.astroh.org/image_test/lightcurve.eps)
>.
>
>I'm using simple commands like
>
>convert lightcurve.eps lightcurve.png
>
>Are there any additional things I can try to get the .png file to look  
>the way I want it to?
>
>Cheers,
>Michael Stroh

Mr. Thyssen worked out the solution in offlist emails with me.
I needed the -flatten option for the png background to be white.

Here is a copy of the solution:
##############################################
On Mon, 27 Oct 2008 15:19:29 +1000
Anthony Thyssen <anthony@...> wrote:

>| >Can you give me a link to lightcurve.eps  for me to play with?
>|
>| It was in the OP's original email to this thread, the link is
>|
>|  http://www.astroh.org/image_test/
>|
>I tryed the above command on the LATEST IM and it generated a PNG
>with transparent background.  Everything was visible.
>
>Could your PNG viewer not understand transparency?
>
>If I don't want transparency I can add a   -background white -flatten
>just before the save file name.
>
>   convert  -density 288  lightcurve.eps  -resize 25% \
>            -background white -flatten  lightcurve.png
>
>
>I really dont see the need to go though a PDF image format!

You are right! Thanks. Upon testing, it is the -flatten option
that seems to do the trick for me.

convert  -density 288  lightcurve.eps  -resize 25%  -flatten lightcurve.png

Thanks, I will post this to the original thread for the benefit of others.

zentara


--
I'm not really a human, but I play one on earth.
http://zentara.net/Remember_How_Lucky_You_Are.html 



--
I'm not really a human, but I play one on earth.
http://zentara.net/Remember_How_Lucky_You_Are.html 
_______________________________________________
Magick-users mailing list
Magick-users@...
http://studio.imagemagick.org/mailman/listinfo/magick-users