ViRuSTriNiTy
ViRuSTriNiTy

Reputation: 5155

How to use ImageResizer HttpModule in an Orchard module?

I want to use the ImageResizer lib (version 4+) in my Orchard module to display PDF thumbnails but i want to use it as an HttpModule instead of using the managed API (like the Orchard.MediaProcessing module).

Therefore i followed the instructions given and adjusted the Web.config accordingly:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    ...
    <section name="resizer" type="ImageResizer.ResizerSection" requirePermission="false" />
  </configSections>

  <resizer>
    <plugins>
      <add name="MvcRoutingShim" />
      <add name="PdfiumRenderer" downloadNativeDependencies="true" />
    </plugins>
  </resizer>

  <system.web>
    ...
    <httpModules>
      ...
      <add name="ImageResizingModule" type="ImageResizer.InterceptModule" />
    </httpModules>
  </system.web>

  <system.webServer>
    ...
    <modules ...>
      ...
      <add name="ImageResizingModule" type="ImageResizer.InterceptModule" />
    </modules>
  </system.webServer>

  <runtime>
    <assemblyBinding ...>
      ...
      <dependentAssembly>
        <assemblyIdentity name="PdfiumViewer" publicKeyToken="91e4789cfb0609e0" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.7.0.0" newVersion="2.7.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>    
</configuration>

Sadly it doesn't work at all, images and PDFs are streamed without change.

So i did the same steps with the Orchard.Web project and suddenly it works but now it is not module specific anymore.

Is there any way to enable ImageResizer in my module only?

Upvotes: 0

Views: 122

Answers (1)

Orchard modules can't declare Http Modules, they are defined at the application level. What you can do is register your own controller/action in your module and use ImageResizer directly.

However the feature is already implemented with some useful Orchard helpers as the Orchard.MediaProcessing module. You'll find an example with this blog post: http://weblogs.asp.net/bleroy/effortlessly-resize-images-in-orchard-1-7

You can also take a look at https://github.com/OrchardCMS/Orchard/blob/dev/src/Orchard.Web/Modules/Orchard.MediaProcessing/Shapes/MediaShapes.cs to see all the other options.

You also have a way to define Profiles from the admin page and reuse these named profiles. A Profile is a set of filters to apply to an image (rotation, watermark, cropping, ...) so you can call it on any image url from your views.

Upvotes: 3

Related Questions