简体   繁体   English

使用C#和ImageMagick在上传时将EPS转换为JPG

[英]Convert EPS to JPG on upload using C# and ImageMagick

I have just come across a scenario where I need to convert EPS files to JPG file on upload. 我刚遇到一种情况,我需要在上传时将EPS文件转换为JPG文件。

What I would preferably like to do is, when uploading the EPS files; 我最想做的是在上传EPS文件时; I would like to keep the original EPS file and save it in background under a folder and also convert the EPS image into JPG and save it in another folder. 我想保留原始EPS文件并将其保存在背景下的一个文件夹中,并将EPS图像转换为JPG并将其保存在另一个文件夹中。

Is this something that can be achieved using C#? 使用C#可以实现吗? If so could someone please direct me in the right direction? 如果可以的话,有人可以指导我正确的方向吗?

I have used ImageMagick and GhostScript and from the command line I can convert EPS into JPG but not sure how should I go embedding it in a C# application and convert EPS into JPG on upload. 我使用过ImageMagick和GhostScript,并且可以从命令行将EPS转换为JPG,但是不确定如何将其嵌入C#应用程序中,并在上传时将EPS转换为JPG。

Any help or any demo doing the same will be a great help. 任何帮助或任何演示都将是一个很大的帮助。

Thanks, Zulfi 谢谢Zulfi

After researching available solutions for a while, I came across this utility that seems to work well. 在研究了可用解决方案一段时间之后,我遇到了这个似乎运行良好的实用程序 It's $200/server. 每台服务器200美元。 VeryDoc's utility does not rely on any third party libraries (unlike other solutions) and it offers conversion between many formats. VeryDoc的实用程序不依赖任何第三方库(与其他解决方案不同),它提供了多种格式之间的转换。 The available command line options: 可用的命令行选项:

C:\>ps2img.exe
-------------------------------------------------------
Description:
Convert PS (Postscript) and EPS to TIF, TIFF, JPG, GIF, PNG, BMP, WMF, EMF, PCX, TGA, etc. formats
Usage: ps2img [options] <-i PS File> [-o Output]
-i [input PS]   : Input PS filename
-o [output file]: Output TIFF filename
-g              : Convert to 8-bit grayscale image file, this option is only available while bitcount equal 8 (-b 8)
-m              : Set output to multi-page TIFF file, the default is output to single page TIFF files
-r [resolution] : Set resolution in generated image files
-r 300          : Set horizontal and vertical resolution to 300 DPI
-r 200x300      : Set horizontal and vertical resolution to 200x300 DPI
-r 204x98       : Set horizontal and vertical resolution to 204x98 DPI
-f [first Page] : First page to convert
-l [last Page]  : Last page to convert
-c [compress]   : Set compression method in generated image files (for tif only)
    -c none     : Create TIFF file without compression
    -c lzw      : Compress TIFF using LZW arithmetic
    -c jpeg     : Compress TIFF using JPEG arithmetic
    -c packbits : Compress TIFF using packbits arithmetic
    -c g3       : Compress TIFF using CCITT G3 arithmetic
    -c g4       : Compress TIFF using CCITT G4 arithmetic
    -c ClassF   : Compress TIFF into Fax compatible ClassF 204x98 format
    -c ClassF196: Compress TIFF into Fax compatible ClassF 204x196 format
-q [quality]    : Set quality in created image files (for jpeg image only)
-b [bit count]  : Set bit count in generated image files
-?              : Help
-------------------------------------------------------
Example:
    ps2img -i C:\input.ps -o C:\output.tif
    ps2img -i C:\input.eps -o C:\output.tif
    ps2img -m -i C:\input.ps -o C:\output.tif
    ps2img -c lzw -i C:\input.ps -o C:\output.tif
    ps2img -q 80 -i C:\input.ps -o C:\output.jpg
    ps2img -b 4 -i C:\input.ps -o C:\output.tif
    ps2img -i C:\input.ps -o C:\output.tif -b 1 -c ClassF -r 204x98 -m
    ps2img -f 1 -l 9 C:\input.ps -o C:\output.jpg
    ps2img -i C:\*.ps -o C:\*.pcx

One alternative, ImageMagick (free) + GhostScript is reportedly expensive at $32,000+/year + a $5,000 setup fee. 据报道 ,ImageMagick(免费)+ GhostScript是一种替代产品,价格昂贵,每年32,000美元,另加5,000美元的安装费。

You may consider parsing the EPS file yourself, honestly. 您可以考虑诚实地自己解析EPS文件。

You can probably find various file format information online, such as wotsit.org (which has been around since the 90s, back when people still wrote what they needed from scratch.) 您可能会在线上找到各种文件格式信息,例如wotsit.org(自90年代以来一直存在,那时人们仍然从头开始编写所需内容。)

This has the upside of not needing to embed external artifacts into your solution, nor incurring licensing costs. 这样做的好处是不需要将外部工件嵌入到您的解决方案中,也不需要产生许可成本。 It obviously has the downside of a personal time investment in research and development. 显然,这花费了个人时间来进行研发。 Afterward, perhaps you can share your code/library with others that doesn't have attribution, copyleft or licensing costs. 之后,也许您可​​以与没有署名,版权保留或许可费用的其他人共享您的代码/库。

Good luck! 祝好运!

using ImageMagickNET.dll through this you can convert the .eps,.ai,.psd,.tga files to .jpg format.. c# code: 通过使用ImageMagickNET.dll,您可以将.eps,.ai,.psd,.tga文件转换为.jpg格式。.c#​​代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using SimplePsd;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Data.SqlClient;
using System.Configuration;
using System.Media;
using System.DirectoryServices;
using System.Diagnostics;
namespace Master_Graphics
{
    public partial class Form1 : Form
    { 

        private SimplePsd.CPSD psd = new SimplePsd.CPSD();
        Process ffmpeg;
        string video;
        string thumb;
        public Form1()
        {
            InitializeComponent();
        }
 private void button4_Click(object sender, EventArgs e)
        {
ffmpeg = new Process();
                ffmpeg.StartInfo.Arguments = "convert \"" + listBox1.SelectedItem.ToString() + "\" -background white -flatten -density 300 -colors 512 -antialias  -normalize -units PixelsPerInch -quality 100 -colorspace RGB -resize 3425x3425  \"D:\\GRAPHICS SEARCH ENGINE\\GRAPHICS IMAGES\\EPS\\" + final + ".jpg\"";
                ffmpeg.StartInfo.FileName = ("C:\\Program Files (x86)\\ImageMagick-6.5.3-Q16\\convert.exe");
                ffmpeg.Start();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM