{"id":19357752,"url":"https://github.com/joomla-framework/image","last_synced_at":"2025-04-23T11:30:36.152Z","repository":{"id":7094520,"uuid":"8385804","full_name":"joomla-framework/image","owner":"joomla-framework","description":"[DEPRECATED] Joomla Framework Image Package","archived":false,"fork":false,"pushed_at":"2022-03-12T19:44:44.000Z","size":863,"stargazers_count":11,"open_issues_count":0,"forks_count":16,"subscribers_count":11,"default_branch":"2.0-dev","last_synced_at":"2024-09-01T02:21:50.542Z","etag":null,"topics":["gd","image","joomla","joomla-framework","php"],"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/joomla-framework.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"joomla","custom":"https://community.joomla.org/sponsorship-campaigns.html"}},"created_at":"2013-02-24T03:23:27.000Z","updated_at":"2022-12-16T22:00:56.000Z","dependencies_parsed_at":"2022-08-19T13:51:25.411Z","dependency_job_id":null,"html_url":"https://github.com/joomla-framework/image","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joomla-framework%2Fimage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joomla-framework%2Fimage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joomla-framework%2Fimage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joomla-framework%2Fimage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joomla-framework","download_url":"https://codeload.github.com/joomla-framework/image/tar.gz/refs/heads/2.0-dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223922117,"owners_count":17225636,"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":["gd","image","joomla","joomla-framework","php"],"created_at":"2024-11-10T07:09:03.932Z","updated_at":"2024-11-10T07:09:04.544Z","avatar_url":"https://github.com/joomla-framework.png","language":"PHP","funding_links":["https://github.com/sponsors/joomla","https://community.joomla.org/sponsorship-campaigns.html"],"categories":[],"sub_categories":[],"readme":"## The Image Package [![Build Status](https://ci.joomla.org/api/badges/joomla-framework/image/status.svg)](https://ci.joomla.org/joomla-framework/image)\n\n[![Latest Stable Version](https://poser.pugx.org/joomla/image/v/stable)](https://packagist.org/packages/joomla/image)\n[![Total Downloads](https://poser.pugx.org/joomla/image/downloads)](https://packagist.org/packages/joomla/image)\n[![Latest Unstable Version](https://poser.pugx.org/joomla/image/v/unstable)](https://packagist.org/packages/joomla/image)\n[![License](https://poser.pugx.org/joomla/image/license)](https://packagist.org/packages/joomla/image)\n\nThis package comprises of 2 main classes, `Image` and `ImageFilter` which has 8 filter sub-classes that it can use to apply a desired filter to your image. `Image` depends on the `GD` php extension to be loaded on your server. More information on `GD` can be found at: https://www.php.net/manual/en/book.image.php\n\nManipulating images in raw PHP using the `GD` image* functions requires a lot of boilerplate code. The intent of this package is to handle those requirements and make it simple for developers to accomplish those tasks through easy to use (and remember) methods.\n\nAll classes in this package are supported by the auto-loader so can be invoked at any time.\n\n### Deprecated\n\nThe `joomla/image` package is deprecated with no future updates planned.\n\n### Construction\n\nWhen creating a new `Image` object, the constructor will check that the `gd` extension is loaded, and throw a `RuntimeException` if it is not.\n\nThe constructor takes a single optional `$source` parameter. This argument can be one of two things:\n\n- A variable containing an existing, valid image resource created using a `imagecreate*` method.\n- A string containing a valid, absolute path to an image\n\nIf you choose the first option, the class sets the protected property `$handle` to the provided image resource.\nIf you choose the second option, the class will call the `loadFile` method, passing along the `$source` parameter.\n\n```php\nuse Joomla\\Image\\Image;\n\n// Creating a new Image object, passing it an existing handle.\n$resource = imagecreate(100, 100);\n$image = new Image($resource);\n\n// Creating a new Image object, passing it an image path\n$image = new Image(JPATH_ROOT . '/media/com_foo/images/uploads/bar.png');\n\n// Creating a new Image object then manually calling `loadFile`\n$image = new Image;\n$image-\u003eloadFile(JPATH_ROOT . '/media/com_foo/images/uploads/bar.png');\n```\n\n### Usage\n\nKeep in mind that most public methods return a `Image` instance with a valid image handle for easy method chaining. The examples for each method will break each method call out to be able to comment on what the code is doing, but production code can be chained like so (if you prefer):\n\n```php\nuse Joomla\\Image\\Image;\n\n$image = new Image();\n$image-\u003eloadFile(JPATH_ROOT . '/path/to/image.png')\n\t-\u003ecrop(600, 250)\n\t-\u003etoFile(JPATH_ROOT . '/tmp/image.png');\n```\n\nSince Platform version 12.3, there is a new `destroy()` method that gets called in appropriate places throughout the class which runs the `imagedestroy` function to free memory associated with an image handle. This method is called before each time an image handle is replaced (when `$createNew` is set to false) as well as in the class `__descruct` method as a final cleanup.\n\n#### The `resize` method\n__Accepted Parameters__\n\n- `$width`: The width of the resized image in pixels or a percentage.\n- `$height`: The height of the resized image in pixels or a percentage.\n- `$createNew`: If true the current image will be cloned, resized and returned; else the current image will be resized and returned.\n- `$scaleMethod`: Which method to use for scaling\n\nExample: Using `Image::resize()` to generate a resized image.\n\n```php\nuse Joomla\\Image\\Image;\n\n// Create our image object\n$image = new Image(JPATH_ROOT . '/media/com_foo/images/uploads/bar.png');\n\n// Resize the image using the SCALE_INSIDE method\n$image_resized = $image-\u003eresize(300, 150, true, Image::SCALE_INSIDE);\n\n// Write it to disk\n$image_resized-\u003etoFile(JPATH_ROOT . '/tmp/bar_resized.png');\n\n```\n\n\n#### The `crop` method\n__Accepted Parameters__\n\n- `$width`: The width of the image section to crop in pixels or a percentage.\n- `$height`: The height of the image section to crop in pixels or a percentage.\n- `$left`: The number of pixels from the left to start cropping.\n- `$top`: The number of pixels from the top to start cropping.\n- `$createNew`: If true the current image will be cloned, cropped and returned; else the current image will be cropped and returned.\n\nExample: Using `Image::crop()` to generate a cropped image.\n\n```php\nuse Joomla\\Image\\Image;\n\n// Create our image object\n$image = new Image(JPATH_ROOT . '/media/com_foo/images/uploads/bar.png');\n\n// Crop the image to 150px square, starting 10 pixels from the left, and 20 pixels from the top\n$image_resized = $image-\u003ecrop(150, null, 10, 20);\n\n// Write it to disk\n$image_resized-\u003etoFile(JPATH_ROOT . '/tmp/bar_cropped.png');\n```\n\nTo crop in image after resizing it to maintain proportions use `cropResize` method with familiar arguments `$width`, `$height` and `$createNew`.\n\n\n#### The `createThumbs` method\n__Accepted Parameters__\n\n- `$thumbSizes`: String or array of strings. Example: $thumbSizes = array('150x75','250x150');\n- `$creationMethod`: See __Resize Methods__ below.\n- `$thumbsFolder`: Destination for thumbnails. Passing null generates a thumbs folder in the loaded image's containing folder.\n\nExample: Using `Image::createThumbs()` to generate thumbnails of an image.\n\n```php\nuse Joomla\\Image\\Image;\n\n// Set the desired sizes for our thumbnails.\n$sizes = array('300x300', '64x64', '250x125');\n\n// Create our object\n$image = new Image(JPATH_ROOT . '/media/com_foo/images/uploads/uploadedImage.jpg');\n\n// Create the thumbnails\n$image-\u003ecreateThumbs($sizes, Image::SCALE_INSIDE);\n```\n\nIn this example, we use the `createThumbs` method of `Image`. This method takes 2 parameters. The first parameter can be a string containing a single size in `WIDTHxHEIGHT` format, or it can be an array of sizes in the format (as shown in the example). The second parameter specifies the resize method. (See Resize Methods below)\n\nTo receive Image instances without saving them to disk, use `generateThumbs` method with arguments `$thumbSizes` and `$creationMethod`.\n\n\n#### Resize Methods\n\nThe `resize`, `createThumbs` and `generateThumbs` methods take an optional parameter that defines what method to use when scaling an image.\nThis parameter can be one of the following:\n\n- `Image::SCALE_FILL` - Gives you a thumbnail of the exact size, stretched or squished to fit the parameters.\n- `Image::SCALE_INSIDE` - Fits your thumbnail within your given parameters. It will not be any taller or wider than the size passed, whichever is larger.\n- `Image::SCALE_OUTSIDE` - Fits your thumbnail to the given parameters. It will be as tall or as wide as the size passed, whichever is smaller.\n- `Image::SCALE_FIT` - Fits your thumbnail to given boundaries maintaining aspect ratio. Result will be aligned vertically to center and horizontally to middle.\n- `Image::CROP` - Gives you a thumbnail of the exact size, cropped from the center of the full sized image.\n- `Image::CROP_RESIZE` - As above, but gives a clean resize and crop from center.\n\n\n#### The `toFile` method\n__Accepted Parameters__\n\n- `$path`: The filesystem path to save the image.\n           When null, the raw image stream will be outputted directly.\n- `$type`: The image type to save the file as (`IMAGETYPE_GIF`|`IMAGETYPE_PNG`|`IMAGETYPE_JPEG`).\n- `$options`: The image type options to use in saving the file.\n              Use `quality` key to set compression level (0..9 for PNGs and 0..100 for JPEGs)\n\nExample: Using `Image::toFile()` to save the image as JPEG with 65 compression level\n\n```php\nuse Joomla\\Image\\Image;\n\n// Create our object\n$image = new Image(JPATH_ROOT . '/media/com_foo/images/uploads/bar.png');\n\n// Write to disk\n$image-\u003etoFile(JPATH_ROOT . '/tmp/bar.jpg', IMAGETYPE_JPEG, array('options' =\u003e 65));\n\n```\n\nExample: Using `Image::toFile()` to retrieve data blob of an image.\n\n```php\nuse Joomla\\Image\\Image;\n\n// Create our object\n$image = new Image(JPATH_ROOT . '/media/com_foo/images/uploads/bar.png');\n\n// Enable output buffering\nob_start();\n\n// Retrieve data blob\n$image-\u003etoFile(null, IMAGETYPE_PNG);\n$imageBlob = ob_get_clean();\n```\n\n\n## Installation via Composer\n\nAdd `\"joomla/image\": \"2.0.*@dev\"` to the require block in your composer.json and then run `composer install`.\n\n```json\n{\n\t\"require\": {\n\t\t\"joomla/image\": \"2.0.*@dev\"\n\t}\n}\n```\n\nAlternatively, you can simply run the following from the command line:\n\n```sh\ncomposer require joomla/image \"2.0.*@dev\"\n```\n\nIf you want to include the test sources, use\n\n```sh\ncomposer require --prefer-source joomla/image \"~1.0\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoomla-framework%2Fimage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoomla-framework%2Fimage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoomla-framework%2Fimage/lists"}