{"id":20022144,"url":"https://github.com/modxcms/resizer","last_synced_at":"2026-03-01T07:31:13.135Z","repository":{"id":10253996,"uuid":"12362318","full_name":"modxcms/Resizer","owner":"modxcms","description":"A lightweight, modern image resizer for MODX","archived":false,"fork":false,"pushed_at":"2019-09-10T06:56:55.000Z","size":659,"stargazers_count":20,"open_issues_count":16,"forks_count":13,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-04-28T12:26:18.478Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/modxcms.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-08-25T16:58:57.000Z","updated_at":"2022-08-31T18:40:53.000Z","dependencies_parsed_at":"2022-08-29T14:51:35.958Z","dependency_job_id":null,"html_url":"https://github.com/modxcms/Resizer","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modxcms%2FResizer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modxcms%2FResizer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modxcms%2FResizer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modxcms%2FResizer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/modxcms","download_url":"https://codeload.github.com/modxcms/Resizer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252423078,"owners_count":21745541,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T08:39:19.734Z","updated_at":"2026-03-01T07:31:13.094Z","avatar_url":"https://github.com/modxcms.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Resizer v1.0.0-pl\n==========\n\nA simple, modern image resizer for MODX. Built on [Imagine](https://github.com/avalanche123/Imagine), Resizer supports the Gmagick, Imagick and GD extensions and can be considerably faster than phpThumb for image sizing and cropping operations. Available from the MODX [Extras Repo](http://modx.com/extras/package/resizer).\n\nRequirements\n-----------\n\n* PHP 5.3.2 or higher\n* One or more of the following PHP extensions: Gmagick, Imagick (with ImageMagick 6.2.9 or higher), GD 2.0.1 or higher\n\nBoth Imagick and Gmagick offer much better performance and lower memory requirements than GD, especially if you're using a relatively recent version of [ImageMagick](http://www.imagemagick.org/)/[GraphicsMagick](http://www.graphicsmagick.org/).  I think Imagick is the best overall: good performance and good support for all features.  Gmagick is a bit faster but doesn’t have full support for opacity, though this only matters if you’re adding partially transparent backgrounds to PNGs or using watermarks.  If your site does lots of image resizing—especially thumbnailing large jpegs—Imagick or Gmagick will be _much_ faster.\n\nUsage\n-----\n\nResizer is a PHP class and can only be called from a snippet.  If you’re not developing your own snippet you’ll probably want to install a higher-level package which supports Resizer, like [pThumb](https://github.com/oo12/phpThumbOf).\n\n### pThumb\n\nChange the ```phpthumbof.use_resizer``` system setting to Yes to enable Resizer globally, or use ```[[pthumb? \u0026useResizer=`1` ...]]``` for a particular instance.  See the [Options](#options) section below for supported options.  Other than that, use it just like you always have.\n\n### Snippet Developers\n\nSample code:\n\n    $modx-\u003eloadClass('Resizer', MODX_CORE_PATH . 'components/resizer/model/', true, true);\n    $resizer = new Resizer($modx);  // pass in the modX object\n    $resizer-\u003edebug = true;  // (optional) Enable debugging messages.\n    $resizer-\u003eprocessImage(\n    \t'/full/path/input-image.png',  // input image file. Path can be absolute or relative to MODX_BASE_PATH\n    \t'relative/path/output-image.jpg',  // output image file. Extension determines image format\n        array('w' =\u003e 600, 'scale' =\u003e 1.5)  // or 'w=600\u0026scale=1.5' instead of an array\n    );\n    // (optional) Write debug message array to the MODX error log\n    $modx-\u003elog(modX::LOG_LEVEL_ERROR, 'Resizer debug output' . substr(print_r($resizer-\u003edebugmessages, TRUE), 7, -2);\n\n\n\nOptions\n--------\n\nResizer only supports a subset of [phpThumb options](http://phpthumb.sourceforge.net/demo/docs/phpthumb.readme.txt), the most useful and commonly used ones.  Many of phpThumb’s options are arguably better handled now or in the near future with CSS transforms and filters anyway, so I haven’t implemented these.  But if there’s one you’ve just _got_ to have, open an issue.\n\n### Supported phpThumb Options\n\n\u003ctable\u003e\n\t\u003ctr\u003e\u003cth\u003eOption\u003c/th\u003e\u003cth\u003eDescription\u003c/th\u003e\u003cth\u003eValue/Unit\u003c/th\u003e\u003c/tr\u003e\n\t\u003ctr\u003e\u003ctd\u003e\u003cb\u003ew\u003c/b\u003e\u003c/td\u003e\u003ctd\u003emax width\u003c/td\u003e\u003ctd\u003epixels\u003c/td\u003e\u003c/tr\u003e\n\t\u003ctr\u003e\u003ctd\u003e\u003cb\u003eh\u003c/b\u003e\u003c/td\u003e\u003ctd\u003emax height\u003c/td\u003e\u003ctd\u003epixels\u003c/td\u003e\u003c/tr\u003e\n\t\u003ctr\u003e\u003ctd\u003e\u003cb\u003ewl\u003c/b\u003e\u003c/td\u003e\u003ctd\u003emax width: landscape orientation. If an image is wider than it is tall, a value for \u003cb\u003ewl\u003c/b\u003e will override one for \u003cb\u003ew\u003c/b\u003e. This and the following 5 options are broken in phpThumb but work in Resizer.\u003c/td\u003e\u003ctd\u003epixels\u003c/td\u003e\u003c/tr\u003e\n\t\u003ctr\u003e\u003ctd\u003e\u003cb\u003ehl\u003c/b\u003e\u003c/td\u003e\u003ctd\u003emax height: landscape orientation\u003c/td\u003e\u003ctd\u003epixels\u003c/td\u003e\u003c/tr\u003e\n\t\u003ctr\u003e\u003ctd\u003e\u003cb\u003ewp\u003c/b\u003e\u003c/td\u003e\u003ctd\u003emax width: portrait orientation\u003c/td\u003e\u003ctd\u003epixels\u003c/td\u003e\u003c/tr\u003e\n\t\u003ctr\u003e\u003ctd\u003e\u003cb\u003ehp\u003c/b\u003e\u003c/td\u003e\u003ctd\u003emax height: portrait orientation\u003c/td\u003e\u003ctd\u003epixels\u003c/td\u003e\u003c/tr\u003e\n\t\u003ctr\u003e\u003ctd\u003e\u003cb\u003ews\u003c/b\u003e\u003c/td\u003e\u003ctd\u003emax width: square\u003c/td\u003e\u003ctd\u003epixels\u003c/td\u003e\u003c/tr\u003e\n\t\u003ctr\u003e\u003ctd\u003e\u003cb\u003ehs\u003c/b\u003e\u003c/td\u003e\u003ctd\u003emax height: square\u003c/td\u003e\u003ctd\u003epixels\u003c/td\u003e\u003c/tr\u003e\n\t\u003ctr\u003e\u003ctd\u003e\u003cb\u003esw\u003c/b\u003e\u003c/td\u003e\u003ctd\u003eSource crop: Width. A source crop is applied to the input image before any of the other sizing or cropping operations are performed. For this and the following three options, values 1 or greater are interpreted as pixels and values between 0 and 1 as percentages, similar to phpThumb. Default: 100%\u003c/td\u003e\u003ctd\u003epixels (or % if \u0026lt; 1)\u003c/td\u003e\u003c/tr\u003e\n\t\u003ctr\u003e\u003ctd\u003e\u003cb\u003esh\u003c/b\u003e\u003c/td\u003e\u003ctd\u003eSource crop: Height. Default: 100%\u003c/td\u003e\u003ctd\u003epixels (or % if \u0026lt; 1)\u003c/td\u003e\u003c/tr\u003e\n\t\u003ctr\u003e\u003ctd\u003e\u003cb\u003esx\u003c/b\u003e\u003c/td\u003e\u003ctd\u003eSource crop: left side. sx and sy control the starting point for the crop box. Resizer will adjust this value if needed to keep the right side from going past the opposite edge of the image. Default: center crop\u003c/td\u003e\u003ctd\u003epixels (or % if \u0026lt; 1)\u003c/td\u003e\u003c/tr\u003e\n\t\u003ctr\u003e\u003ctd\u003e\u003cb\u003esy\u003c/b\u003e\u003c/td\u003e\u003ctd\u003eSource crop: top side. Default: center crop\u003c/td\u003e\u003ctd\u003epixels (or % if \u0026lt; 1)\u003c/td\u003e\u003c/tr\u003e\n\t\u003ctr\u003e\u003ctd\u003e\u003cb\u003eaoe\u003c/b\u003e\u003c/td\u003e\u003ctd\u003eAllow Output Enlargement. Turning this on will allow the output image to be interpolated up if the requested size exceeds the resolution of the input image.\u003c/td\u003e\u003ctd\u003e\u003cb\u003e1\u003c/b\u003e or \u003cb\u003e0\u003c/b\u003e (default: \u003cb\u003e0\u003c/b\u003e)\u003c/td\u003e\u003c/tr\u003e\n\t\u003ctr\u003e\u003ctd\u003e\u003cb\u003ebg\u003c/b\u003e\u003c/td\u003e\u003ctd\u003eBackground Color. Specifies a background color for input images with transparency or when extending the background with \u003cb\u003efar\u003c/b\u003e. Colors are specified with 3- or 6-digit hex values, just like CSS. A leading # is optional. Also optional is an opacity value (0–100) at the end, separated by a /. Opacity only applies if the output format is PNG. Examples: #a00, 333333, F9AE90/75\u003c/td\u003e\u003ctd\u003e\u003c/td\u003e\u003c/tr\u003e\n\t\u003ctr\u003e\u003ctd\u003e\u003cb\u003efar\u003c/b\u003e\u003c/td\u003e\u003ctd\u003eForce Aspect Ratio. Width and height must both be specified. Scales an image to fit inside the box specified by width and height, then adds a solid color (white by default, or \u003cb\u003ebg\u003c/b\u003e) if necessary to make the output image exactly width x height. The value given indicates how the image will be positioned inside the box. l=left, r=right, t=top, b=bottom, c=center\u003c/td\u003e\u003ctd\u003e\u003cb\u003etl\u003c/b\u003e, \u003cb\u003et\u003c/b\u003e, \u003cb\u003etr\u003c/b\u003e\u003cbr\u003e\u003cb\u003el\u003c/b\u003e, \u003cb\u003ec\u003c/b\u003e, \u003cb\u003er\u003c/b\u003e\u003cbr\u003e\u003cb\u003ebl\u003c/b\u003e, \u003cb\u003eb\u003c/b\u003e, \u003cb\u003ebr\u003c/b\u003e\u003c/td\u003e\u003c/tr\u003e\n\t\u003ctr\u003e\u003ctd\u003e\u003cb\u003eq\u003c/b\u003e\u003c/td\u003e\u003ctd\u003eJPEG quality\u003c/td\u003e\u003ctd\u003einteger (default: \u003cb\u003e75\u003c/b\u003e)\u003c/td\u003e\u003c/tr\u003e\n\t\u003ctr\u003e\u003ctd\u003e\u003cb\u003ezc\u003c/b\u003e\u003c/td\u003e\u003ctd\u003eZoom Crop. Sizes an image to fill the given box (both a width and a height must be specified) and crops off any extra.  The value indicates the portion of the image you’d like to retain: top left, center, bottom right, etc. (You can also use \u003cb\u003e1\u003c/b\u003e for center.) Overrides \u003cb\u003efar\u003c/b\u003e. Unlike with phpThumb, all these options work with GD as well.\u003c/td\u003e\u003ctd\u003e\u003cb\u003etl\u003c/b\u003e, \u003cb\u003et\u003c/b\u003e, \u003cb\u003etr\u003c/b\u003e\u003cbr\u003e\u003cb\u003el\u003c/b\u003e, \u003cb\u003ec\u003c/b\u003e, \u003cb\u003er\u003c/b\u003e\u003cbr\u003e\u003cb\u003ebl\u003c/b\u003e, \u003cb\u003eb\u003c/b\u003e, \u003cb\u003ebr\u003c/b\u003e\u003c/td\u003e\u003c/tr\u003e\n\t\u003ctr\u003e\u003ctd\u003e\u003cb\u003efltr[]=usm\u003c/b\u003e\u003c/td\u003e \u003ctd\u003eUnsharp mask. Amount, radius and threshold are fixed and can’t be specified.\u003c/td\u003e \u003ctd\u003e\u003c/td\u003e\u003c/tr\u003e\n\t\u003ctr\u003e\u003ctd\u003e\u003cb\u003efltr[]=wmt\u003c/b\u003e\u003c/td\u003e \u003ctd\u003eText watermark. Parameters mostly follow \u003ca href=\"https://github.com/JamesHeinrich/phpThumb/blob/adcaf2f0d18f331c44eafa7bc359f8d47d1ae235/docs/phpthumb.readme.txt#L367\"\u003ephpThumb\u003c/a\u003e, except tiling isn’t supported. The font path should be absolute, or relative to MODX assets path, core path, or {core path}/model/phpthumb/fonts. Leave the font blank for the default, Fira Sans.\u003c/td\u003e \u003ctd\u003e\u003c/td\u003e\u003c/tr\u003e\n\t\u003ctr\u003e\u003ctd\u003e\u003cb\u003efltr[]=wmi\u003c/b\u003e\u003c/td\u003e \u003ctd\u003eImage watermark. Parameters mostly follow \u003ca href=\"https://github.com/JamesHeinrich/phpThumb/blob/adcaf2f0d18f331c44eafa7bc359f8d47d1ae235/docs/phpthumb.readme.txt#L346\"\u003ephpThumb\u003c/a\u003e, except tiling isn’t supported. The watermark image path should be absolute, or relative to MODX assets path, core path, or {core path}/model/phpthumb/images.\u003c/td\u003e \u003ctd\u003e\u003c/td\u003e\u003c/tr\u003e\n\u003c/table\u003e\n\n*Output file type* — Resizer doesn’t explicitly support phpThumb’s \u003cb\u003ef\u003c/b\u003e option, but instead infers the proper image type from the output filename’s extension. Some wrappers like pThumb handle the \u003cb\u003ef\u003c/b\u003e option in the usual way.\u003cbr\u003e  Supported formats: jpg (or jpeg), png, gif, wbmp, xbm.\n\n### New Options\n\n\u003ctable\u003e\n\t\u003ctr\u003e\u003cth\u003eOption\u003c/th\u003e\u003cth\u003eDescription\u003c/th\u003e\u003cth\u003eValue/Unit\u003c/th\u003e\u003c/tr\u003e\n\t\u003ctr\u003e\u003ctd\u003e\u003cb\u003escale\u003c/b\u003e\u003c/td\u003e\u003ctd\u003eConvenient when creating retina images. Any dimensions given will be multiplied by this number internally. If \u003cb\u003eaoe\u003c/b\u003e is off—the default—and the input image doesn’t have sufficient resolution, \u003cb\u003escale\u003c/b\u003e will be adjusted downward so you get as much output resolution as possible without scaling the image up.\u003c/td\u003e\u003ctd\u003enumber \u0026gt; 1\u003c/td\u003e\u003c/tr\u003e\n\t\u003ctr\u003e\u003ctd\u003e\u003cb\u003eqmax\u003c/b\u003e\u003c/td\u003e\u003ctd\u003eAn upper limit jpeg quality. If the requested size exceeds the input image resolution and \u003cb\u003eaoe\u003c/b\u003e is off, Resizer can increase the jpeg quality in an attempt to compensate. Quality begins at q (input resolution = output resolution) and reaches qmax when the input resolution is 1/2 of the requested output resolution.\u003c/td\u003e\u003ctd\u003e1–100 (should be greater than q)\u003c/td\u003e\u003c/tr\u003e\n\u003c/table\u003e\n\n\nSettings\n--------\n\nResizer provides one system setting, ```resizer.graphics_library```.  Normally you’ll leave this set at **2** (auto).  In that case Resizer will check the following extensions in this order and pick the first one it finds: Imagick, Gmagick, GD. Setting it to **1** will restrict it to Gmagick or GD, **0** to GD only.\n\n\nAn Example with Retina Images\n-----------------------\n\n**scale** and **qmax** are designed to help when working with high-dpi (“Retina”) images.  As an example, say you have several images on a page which should each be 600px x 400px but you’d like to increase the images’ natural size to look good on a retina display.  You want to use the trick of a large—2x, say—image size with a low quality setting in order to get sharper images without making them too big.  However, the client is suppling the images and they may not all be a minimum of 1200px x 800px. In fact some may be quite a bit smaller.  There's no point in scaling these up on the server, but reducing the jpeg quality will make them look worse than they do already.  Here’s where the new options come in.\n\nYou might use these options: **width**:600, **height**:400, **zc**:1, **scale**:2, **q**:55, **qmax**:75.\n\n**scale** makes it easy to adjust the natural size.  If you later decide 1.6x will be better than 2x, just do a search and replace.  If you have multiple images and especially if they’re different sizes, this is much easier than figuring out what size each should be on the page, then multiplying each width and height by the new scale and editing all the **w** and **h** options.  **scale** will adjust downward if there’s not enough input resolution.  So if the original image is only 1000px x 700px **scale** will slide down to 1.67 and the output image will be 1000px x 667px.\n\n**qmax** lets the jpeg quality slide up as if the input image isn’t big enough.  If it’s only a little too small then **q** will increase only a little. Say the client uploads two images: one 1100px x 750px and one 300px x 200px.  The first one has almost all the resolution we need; it’ll come out 1100 x 733 with **q** set to 61.  The second image is way too small: 0.06 MP (megapixels) when we need 0.96 MP.  Since it’s less than 1/2 the resolution we’re looking for, its **q** is set to 75 (our **qmax** setting).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmodxcms%2Fresizer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmodxcms%2Fresizer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmodxcms%2Fresizer/lists"}