Converting EPS to jpg with jagged edge issue

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
janebrandhub
Posts: 17
Joined: 2017-05-31T20:26:05-07:00
Authentication code: 1151

Converting EPS to jpg with jagged edge issue

Post by janebrandhub »

I try to convert EPS to jpg with simple command:
magick -density "300" -colorspace "sRGB" input.eps -resize "1000x1000" -background "#ffffff" -flatten output.jpg
But the output jpg has jagged edge in the bottom. The original eps file link:
https://www.dropbox.com/s/hqywk7ncnun2n ... 2.eps?dl=0
Am i doing something wrong?
I am on IM 7.0.6-Q16 and Ghostscript 9.21.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Converting EPS to jpg with jagged edge issue

Post by fmw42 »

Please refer back to your question a few weeks ago and the bug report and solution for IM 7 at the following links.

viewtopic.php?f=1&t=32469
https://www.imagemagick.org/discourse-s ... =3&t=32497

If you want the background to be transparent, use this:

Code: Select all

magick -density 300 -colorspace srgb test2.eps -alpha transparent -clip -alpha opaque +clip -resize 1000x1000 -strip test2_result1.png
Image

If you want the background to be white, use this:

Code: Select all

magick -density 300 -colorspace srgb test2.eps -alpha transparent -clip -alpha opaque +clip -resize 1000x1000 -strip -background white -flatten test2_result2.png
Image

That works fine for me on IM 7.0.6.8 Q16 HDRI Mac OS X
janebrandhub
Posts: 17
Joined: 2017-05-31T20:26:05-07:00
Authentication code: 1151

Re: Converting EPS to jpg with jagged edge issue

Post by janebrandhub »

This issue is different. I only need to convert eps to jpg(not png) which i can use on website, and i don't need to do "-alpha transparent -clip -alpha opaque +clip".
But simple convert script will cause jagged edge:
magick -density "300" -colorspace "sRGB" input.eps -resize "1000x1000" -background "#ffffff" -flatten output.jpg

Any idea?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Converting EPS to jpg with jagged edge issue

Post by fmw42 »

Imagemagick 7 sometime works differently from Imagemagick 6.

Your input has transparency, so you should likely do it as I mentioned above and just change the output format to jpg rather than png.
janebrandhub
Posts: 17
Joined: 2017-05-31T20:26:05-07:00
Authentication code: 1151

Re: Converting EPS to jpg with jagged edge issue

Post by janebrandhub »

That's not going to work. This script should be very simple convert, but it always cause jagged edge with even very simple script:
magick input.eps output.jpg

Is it only because my input eps has transparency?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Converting EPS to jpg with jagged edge issue

Post by fmw42 »

Yes, your input image has transparency, which comes from a clip path in a vector image. It is not like transparency in a raster image. Please try it and make sure it works for you. Let us know if it does not.

FYI, for IM 6 the syntax used to be as describe here when there was a clip path, but for IM 7 you must add +clip. See http://www.imagemagick.org/Usage/masking/#clip. Even though that example is tiff, the same applies to eps.
janebrandhub
Posts: 17
Joined: 2017-05-31T20:26:05-07:00
Authentication code: 1151

Re: Converting EPS to jpg with jagged edge issue

Post by janebrandhub »

the reason why it's not working is i will write a general convert script to convert different types of images into small size jpeg, so they can be used on website. This convert script works well for most of image types: tiff, pdf, even eps. But only for certain eps images, the converted jpeg file has jagged edge. If that's because the input eps has transparency, then how can i ignore the transparency and get a smooth output jpg ? I can't add "-alpha transparent -clip -alpha opaque" in the general script since most of images don't even have clipping path.
I also try to use photoshop to export the eps as jpg and doesn't have any jagged edge.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Converting EPS to jpg with jagged edge issue

Post by fmw42 »

Use this code and it will process properly and make the background white.

Code: Select all

magick -density 300 -colorspace srgb test2.eps -alpha transparent -clip -alpha opaque +clip -resize 1000x1000 -strip -background white -flatten test2_result2.png
Does that work for non-transparent images?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Converting EPS to jpg with jagged edge issue

Post by fmw42 »

This works for me on IM 7.0.6.9 Q16 Mac OSX, if all you want is a white background.

Code: Select all

magick -density 300 test2.eps -resize 1000x1000 test2_white.png
Image
jpeni
Posts: 9
Joined: 2015-01-12T14:56:33-07:00
Authentication code: 6789
Location: Uniondale NY, USA

Re: Converting EPS to jpg with jagged edge issue

Post by jpeni »

I just finished researching a way I could convert some 60,000 EPS files to raster format and (through research and testing) produced the following Powershell script that converts recursively from EPS to Raster (JPG, PNG, etc). I hope you can use it.

Two things I discovered when converting Vector to Raster (1) When converting VECTOR files, the density setting (ie -density 330) should come BEFORE the vector files in the script or the result will be blurry, (2) If possible, dont resize in the conversion script as the output may not be perfect - I resize images after the conversion.

If you dont know how to use a Powershell script - do some research - there are many intros and tutorials on the web.

Code: Select all

#-----------------------------------------------------------------------------------------------------------------------------
# Powershell script to recursively convert VECTOR to RASTER formats with ImageMagick and Powershell
# Configuration
$srcfolder = "C:\test\pics"
$destfolder = "C:\test\pics\output"

$im_convert_exe = "convert.exe -density 300"
# with VECTOR files the density setting should come 
# BEFORE the vector file or image will be blurry
# change src_filter to the format of the source files
$src_filter = "*.eps"
# change dest_ext to the format of the destination files
$dest_ext = "jpg"
$options = "-depth 8 -alpha off"
$logfile = "C:\test\convert.log"
# ----------------------------------------

$fp = New-Item -ItemType file $logfile -force
$count=0
foreach ($srcitem in $(Get-ChildItem $srcfolder -include $src_filter -recurse))
{
    $srcname = $srcitem.fullname

    # Construct the filename and filepath for the output
    $partial = $srcitem.FullName.Substring( $srcfolder.Length )
    $destname = $destfolder + $partial
    $destname= [System.IO.Path]::ChangeExtension( $destname , $dest_ext )
    $destpath = [System.IO.Path]::GetDirectoryName( $destname )

    # Create the destination path if it does not exist
    if (-not (test-path $destpath))
    {
        New-Item $destpath -type directory | Out-Null
    }

    # Perform the conversion by calling an external tool
    $cmdline =  $im_convert_exe + " `"" + $srcname  + "`"" + $options + " `"" + $destname + "`" " 
    #echo $cmdline
    invoke-expression -command $cmdline

    # Get information about the output file    
    $destitem = Get-item $destname

    # Show and record information comparing the input and output files
    $info = [string]::Format( "{0} `t {1} `t {2} `t {3} `t {4} `t {5}", $count, 
	$partial, $srcname, $destname, $srcitem.Length ,  $destitem.Length)
    echo $info
    Add-Content $fp $info

    $count=$count+1
} 
#------------------------------------------------------------------------------------------------
NOTE: Make sure ImageMagick is fully installed and Windows convert.exe is deleted or disabled so it does not interfere with running ImageMagick "convert".
janebrandhub
Posts: 17
Joined: 2017-05-31T20:26:05-07:00
Authentication code: 1151

Re: Converting EPS to jpg with jagged edge issue

Post by janebrandhub »

Tried different ways and still can't figure out this issue. But i do know why your command:
"magick -density 300 test2.eps -resize 1000x1000 test2_white.png"
doesn't have jagged issue is because the resize is not big enough. When i use
"magick -density 300 test2.eps -resize 1754x2480 output.jpg", it has very jagged edge at the bottom.
How do i fix this antialiasing issue if i want to resize to an A5 jpg?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Converting EPS to jpg with jagged edge issue

Post by fmw42 »

If you do

Code: Select all

magick -density 300 test2.eps test2.png
The resulting image size is 1240x3431, which is smaller than your desired size of 1754x2480. So when you resize, you are magnifying the image which enhances the aliasing (stair-steps). The way to get around it is to increase the density. For example

Code: Select all

magick -density 1200 test2.eps test2.png
Results in a size of 4960x13724. This is more than 2x larger than your desired size. So if we do that again with your resize:

Code: Select all

magick -density 1200 test2.eps -resize 1754x2480 test2.png
It looks nice and smooth to me.
janebrandhub
Posts: 17
Joined: 2017-05-31T20:26:05-07:00
Authentication code: 1151

Re: Converting EPS to jpg with jagged edge issue

Post by janebrandhub »

Thank you very much. I didn't check original eps width smaller than A5, so magnifying caused the aliasing. Now the problem is solved.
janebrandhub
Posts: 17
Joined: 2017-05-31T20:26:05-07:00
Authentication code: 1151

Re: Converting EPS to jpg with jagged edge issue

Post by janebrandhub »

But now i have another issue with the output jpg. My resize script:
magick -density 1200 -colorspace "CMYK" input.eps -density "300" -resize "1754x2480" -flatten -quality 95 output.jpg
The output.jpg quality is good enough, but file size is twice more than generated by photoshop. I am not using "strip" since it's hires cmyk jpg.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Converting EPS to jpg with jagged edge issue

Post by snibgo »

If you want a smaller file size, you can reduce the quality number, eg to 90.
snibgo's IM pages: im.snibgo.com
Post Reply