在Ubuntu上运行ASP.NET 5的Ubuntu上使用MVC 6调整图像大小 [英] Resize images with MVC 6 on Ubuntu running ASP.NET 5 on Mono

查看:75
本文介绍了在Ubuntu上运行ASP.NET 5的Ubuntu上使用MVC 6调整图像大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Ubuntu上运行的带有MONO的ASP.NET 5,MVC 6,DNX451中重新调整图像大小?

我无法解决此问题,因为我使用的标准组件(例如ImageProcessor和ImageResizer.NET)似乎无法正常工作.

解决方案

我目前正在DNX 4.5.1(ASP.NET 5)和MVC 6中开发一个网站,该网站旨在托管在Ubuntu服务器上. /p>

最近,我遇到了调整图像大小的问题,因此我不得不开箱考虑.就我而言,没有必要在开发环境中调整图像大小,因此我专注于如何在即将到来的产品环境中处理图像.

解决方案是使用ImageMagick,这是一个非常好的Linux小软件.

这是我解决的方法:

if (_hostingEnvironment.IsProduction())
{
        var command = "-c 'convert " + filePath + " -resize 960x960 -quality 70 " + filePath + "'";

        Process proc = new System.Diagnostics.Process();
        proc.StartInfo.FileName = "/bin/bash";
        proc.StartInfo.Arguments = command;
        proc.StartInfo.UseShellExecute = false;
        proc.StartInfo.RedirectStandardOutput = false;
        proc.Start();
}

因此,可以通过将文件上传到某个文件夹(在我的情况下为临时文件夹),然后执行convert命令来工作.我用项目中需要的转换参数覆盖了相同的文件.如果您想要更大的图像或更好的质量,可以使用更多的参数.

这是一个不错的解决方案,但是正如我说的,我只专注于在Ubuntu(这将是我的生产环境)上进行这项工作,因此将其封装在if子句中,检查我是否使用prod. ,但是在Windows环境中也可能采用类似的方法,但是我宁愿使用一些标准组件来使之工作.

How can I re-size an image in ASP.NET 5, MVC 6, DNX451, with MONO, running on Ubuntu?

I have been unable to work this out, as the standard components that I have used such as ImageProcessor and ImageResizer.NET seem not to be working.

解决方案

I am currently developing a website in DNX 4.5.1 (ASP.NET 5) and MVC 6, which is meant to be hosted on an Ubuntu server.

Recently I ran in to issues with re-sizing images, so I had to think out of the box. In my case, it was not necessary, to re-size images on my development environment, so I focused on how to handle this on my upcoming prod environment.

The solution was to use ImageMagick, which is a very nice little piece of software for Linux.

This is how I solved it:

if (_hostingEnvironment.IsProduction())
{
        var command = "-c 'convert " + filePath + " -resize 960x960 -quality 70 " + filePath + "'";

        Process proc = new System.Diagnostics.Process();
        proc.StartInfo.FileName = "/bin/bash";
        proc.StartInfo.Arguments = command;
        proc.StartInfo.UseShellExecute = false;
        proc.StartInfo.RedirectStandardOutput = false;
        proc.Start();
}

So this works by uploading the file to some folder, in my case a temporary folder, then I execute the convert command. I overwrite the same file with the conversion parameters that I need in my project. You can use more parameters, if you want larger images or better quality.

This is a nice solution, but as I said, I have only focused on making this work on Ubuntu, which will be my production environment, and therefor it is encapsulated in an if clause, checking whether I am on prod or not, but a similar approach could probably also be possible in Windows environments, but I would rather go for some standard component to make that work.

这篇关于在Ubuntu上运行ASP.NET 5的Ubuntu上使用MVC 6调整图像大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆