We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 39159
    • 23 Posts
    Hello everyone,

    I've got a couple smaller sites on WP - it's a popular blogging platform so why not. One of the plugins that I find works very well is the Smush.it one, which basically losslessly (is that a word?) compresses all your images when you upload them. As far as I know Smush.it doesn't have an API, so they are doing it some other way (I'm assuming). My question is this... is it possible to develop something like this for Modx? Anyone know of anything like this or any plans for it? I'd do it myself but I don't know almost anything about php.
      • 36924 ☆ A M B ☆
      • 298 Posts
      Will be beautiful to see what contributions we get
        • 3749
        • 24,544 Posts
        You can often take a plugin that works on WordPress and modify it to be installed as a package in MODX. How much work it is depends on how the plugin is written.

        That said, I think there are several existing MODX extras that will do the same thing for you. I'll leave it to people more familiar with them to suggest which ones work best.
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 1343 ☆ A M B ☆
          • 2,213 Posts
          I'm unaware of any existing MODX extras that will optimize your images in that manner, sure you could use something like pThumb/phpThumbsUp to optimize the images to a degree. The use of smush.it / kraken.io go beyond normal resizing, however and should be used with care. They can affect the image quality, so applying it manually using the web interfaces would give the best outcome.

          That being said kraken.io does offer an api with paid accounts that could be leveraged. Granted you could look a little higher, services like CloudFlare will cache the images for faster delivery. If you pay they do offer image optimization also stored in their cloud for further performance improvements.
            Patrick | Server Wrangler
            About Me: Website | Tweets |  MODX Hosting
            • 35150 ☆ A M B ☆
            • 191 Posts
            A similar extra could certainly be developed for MODX. However Smush.it doesn't provide a particularly high level of optimization, and sending each image to Smush.it, waiting for it to be processed, then transferring it back could create some real performance problems, especially if Smush.it is flakey. Kraken.io looks interesting, better at least.

            There are a handful of command-line utilities that'll optimize raster graphics well, but you either need to compile them and their dependancies or install a pre-compiled package specific to your server's OS. Plus PHP probably isn't the most suitable language for dealing with this sort of task anyway. So I don't think this approach would work for an easily installable, OS-independent package like a MODX extra.

            For any graphics part of the site's design, I figure the developer should have optimized these manually and shouldn't rely on a plugin to come in later and clean things up. There are a few nice tools like ImageOptim for raster graphics or an online SVG optimizer. If you're using a Grunt workflow there are some comparable Node packages.

            Client- and user-added content is harder. Of course you can use an image resizer like pThumb or phpThumbsUp to at least create properly sized images for the layout, standardize JPEG quality and convert PNGs to JPEGs if needed, but these do little to nothing in the way of micro optimizations.

            If you're using pThumb with Resizer, there is an option to strip out any EXIF metadata and embedded ICC profile (after converting to sRGB of course). That can save several dozen KB on some JPEGs. Beyond that, JPEGs usually can't be losslessly optimized all that much anyway, maybe 3–5% in my experience. PNGs and GIFs certainly can be, but it seems like a lot of user-added content is JPEG anyway (or should be), so the actual return on development effort might end up being rather modest at best.
              Extras :: pThumb • Resizer • imageSlim • setPlaceholders
              • 35150 ☆ A M B ☆
              • 191 Posts
              I've been looking into this some more. There's a similar WordPress plugin EWWW Image Optimizer which looks considerably better, at least in concept. (I haven't used either one.)

              It comes with pre-compiled packages of several optimization tools for the major Linux distributions so optimization can be done locally. This could work for a number of people, and some hosts have these utilities installed to start with. Depending on your server and hosting company though, you may not be able to use them or might have to put in some work getting them installed and operational.

              All the major optimization utilities are open source except for PNGOUT (freeware) and JPEGmini (commercial package), which it doesn't include.

              For people who can't or don't want to mess with installing the command-line utilities, they're working on a web-based service like Smush.it or Kraken.io. At least with Kraken you can use callbacks for the optimization, so they're done asynchronously and wouldn't impact generating and serving pages. I imagine Kraken runs JPEGmini Server too. I don't know how much that costs to license, but it's probably not cheap. Kraken plans run $8–80 a month.

              I wonder how much interest there is in something like this for MODX?

              There's an simple, more manual way to do this too. Use an FTP client like Transmit which supports mounting a server as a drive and dump your images directory onto ImageOptim then JPEGmini. If your site doesn't get a lot of new images added, that'd work just fine.
                Extras :: pThumb • Resizer • imageSlim • setPlaceholders