Comments (15)
To play devil's advocate: why maintain an image library at all, then? Image manipulation is not a core foundation of the framework (such as a router or ORM might be). It is not integrated closely with other parts of the framework, such as the request process. If good user-land packages already exist, what benefits are you providing the community by creating another?
from codeigniter4.
Kudos firstly for this, but If it would be possible, I want to add one more feature that would be awesome:
Cropping Images in PHP Based on their Entropy
Related: https://github.com/stojg/crop
Advantage in practice: User uploads his profile picture and it gets cropped automatically perfectly.
from codeigniter4.
I agree that will be a great addition. I will look into what all it would entail, because it's definitely something I'd love to see be part of it, but I'd have to be able to support it across all supported graphics libraries (GD, ImageMagick, GraphicsMagick?)
from codeigniter4.
GraphicsMagick would be great, imagemagick is slow and for providers is the new fork way better
from codeigniter4.
Recommend that there is a REAL solid game plan with how image manipulation is instantiated and interacted with, with emphasis on:
- Not having the primary "library" class (in CI3 terms) be the wrapper around a single image. Instead, the primary library should be a factory that allows instantiation of individual image wrappers.
- Whether the individual image wrappers should be mutable or immutable.
from codeigniter4.
Excuse my ignorance...
Why can not use for CI4 a third party library for example this:
This library provide all solutions to complete this task and support imagemagick and GD.
We can create a image class that use this library?
Maybe it's crazy....???
from codeigniter4.
@davidgv88 I hadn't seen that library before. And it looks great! But, keeping with a long history of CI being primarily a self-contained framework, we're not pulling in outside libs. The last time I recommended that, didn't go well. :)
That does look like an excellent library to study, though!
from codeigniter4.
And playing the normal Devil's Advocate to your Devil's Advocate:
. If good user-land packages already exist, what benefits are you providing the community by creating another?
Good user-land packages exist for every part of the framework. The often have different philosophies, different ways of working, etc, but they exist and can be wired together. Heck, that's what 1/2 of Laravel is.
I'm not saying this just because I think we should do the whole, "We didn't make it" thing, because, hell, I'm the one who has to build most of it, and this is a long process. :)
I'll be happy to bring it up, because it's not a core part of the framework. It is a part that CI has always had so I think many people see it as belonging in the framework.
And I get what you're saying, and ask myself similar things fairly frequently these days. But, in the end, I'm not the owner of the framework. In many ways the community that's been using it for the last decade (myself included) are the "owners". I'm just the steward tasked with the job of creating a more modern, hopefully better version. In the process, we're porting most of the existing functionality from the old framework into the new, and that's all this library was meant to do: provide existing functionality with some new tweaks that are useful in how today's workflows and needs are. And it might be a little integrated into the Uploader library, though any image library we included could be used...
from codeigniter4.
i think it's important, that CI has its own library, the less external sources the better and to be honest, for all of us it's better to maintain one framework and not always have to update 3rd party extensions, every additional extension is a risk to break something, to add new bugs while updating and much more.
from codeigniter4.
from codeigniter4.
I was playing a bit with the CI 3.x Image_Lib class to extend it functionality for thumbnail creation and noticed two features that I am missing right now. What I was looking for is a method to create a thumbnail of given size (as set in the configuration) while retaining the original image_ratio:
As you see, I have filled the top/bottom (and for other images the side) with a blurred version of the original image to make the image fit the required dimensions. With the original CI 3.x library this is not possible as only one of two dimensions set in the configuration is altually retained if the configuration item "maintain_ratio" is set to true. I have now written a customized version of the Image_Lib library to use within my application. Maybe it can be considered to put similar functionality in the new library if not done so already:
Chaining modifications
In the old CI 3.x it is only possible to save or output the result of a modification directly (via the configuration "dynamic_output"). It would be great to extend this functionality to simply return the image so another modification can be done on the image (e.g. chaining). For e.g. $image->resize()->blur();
.
Gaussian blur
Furthermore, I have written a method to add a gaussian blur to an image for my CI 3.x library (using GD2). Unfortunately, I found out that a simple gaussian blur filter in PHP takes quite some resources. After searching I found an alternative methodology here which I have used to write below method. I hope similar functionality can be included in the CI 4.x library to add to its usefulness.
/**
* Returns the given image with gaussian blur applied
*
* @param $src_img The source image to process (GD2 resource)
* @param $strengh The strength of the blur to apply
* @return Object The resulting image
*/
function blur_gd($src_img, $strength = 3)
{
if ($this->image_library === 'gd2' && function_exists('imagecreatetruecolor'))
{
$create = 'imagecreatetruecolor';
$copy = 'imagecopyresampled';
}
else
{
$create = 'imagecreate';
$copy = 'imagecopyresized';
}
// Determine target dimensions
$originalWidth = imagesx($src_img);
$originalHeight = imagesy($src_img);
$smallestWidth = ceil($originalWidth * 0.5 ** $strength);
$smallestHeight = ceil($originalHeight * 0.5 ** $strength);
// Prepare first iteration
$prevImage = $src_img;
$prevWidth = $originalWidth;
$prevHeight = $originalHeight;
for($i = 0; $i < $strength; $i += 1)
{
// Determine new dimensions
$nextWidth = $smallestWidth * 2 ** $i;
$nextHeight = $smallestHeight * 2 ** $i;
// Scale down & blur image
$nextImage = $create($nextWidth, $nextHeight);
$copy($nextImage, $prevImage, 0, 0, 0, 0, $nextWidth, $nextHeight, $prevWidth, $prevHeight);
imagefilter($nextImage, IMG_FILTER_GAUSSIAN_BLUR);
// Move on...
$prevImage = $nextImage;
$prevWidth = $nextWidth;
$prevHeight = $nextHeight;
}
// Scale back & blur image
$copy($src_img, $nextImage, 0, 0, 0, 0, $originalWidth, $originalHeight, $nextWidth, $nextHeight);
imagefilter($src_img, IMG_FILTER_GAUSSIAN_BLUR);
imagedestroy($prevImage);
return $src_img;
}
from codeigniter4.
Hi @Xirt
In all my projects I never use the CI Image_Lib. ItΒ΄s very basic. I personally always use "Image Intervention" library.
In the blur case, you can use the library that I mentioned before, the example code could be:
$manager = new \Intervention\Image\ImageManager();
$background = $manager->canvas(500, 500);
$img_blur = $manager->make('example.jpeg')->fit(500, 500)->blur(100);
$background->insert($img_blur);
$image = $manager->make('example.jpeg')->resize(500, 500, function ($c) {
$c->aspectRatio();
$c->upsize();
});
// insert resized image centered into background
$background->insert($image, 'center');
// save or do whatever you like
$background->save('example_resized.jpg');
from codeigniter4.
@AntonyGarand Thanks for the comments. Chaining is already being baked in, so you're good there, assuming that nothing comes up to make me rewrite that.
While that's a pretty cool way to handle the thumbnails, it's definitely a stylized way to handle it, so probably not one that I'll provide out of the box. We want to leave it flexible for everyone to match their own style.
I'm undecided about features like blur. Once we start adding features like that we really need to keep going and add features like changing brightness, grayscale, etc And, while I'd love to see that out of the box, as @Portaflex said, ImageIntervention is a great library. And I'm just one man doing this and can't really afford to spend a couple of months (or more) making all of these features work for all supported drivers (gd, ImageMagick, GraphicsMagick, and NetPBM).
from codeigniter4.
Alternatively I could think of having an option to retrieve the Image Resource from the class so that it can be used in other (external or self-written) libraries if required? This way people can use the functionalities available within the CI library, but they can program themselves any functionalities they are missing (or use a different library for that). I could not find an 'official' way to perform this task with CI 3.x, but as you indicated chaining is now possible I can imagine the Image Resource is available internally hence this should now become a possibility.
from codeigniter4.
@Xirt yeah, that should not be a problem at all. And sounds like a great addition. I can add a getter for it. I have a feeling for any extensions, though, you'll probably just extend the correct Handler, which would give you access to the protected class var, anyway.
from codeigniter4.
Related Issues (20)
- Bug: postgre can not connect to database error HOT 12
- `Model::paginate()` behavior when `$page` exceeds the last page HOT 12
- Bug: CodeIgniter v4.5.1 When I connect Postgres Database I Received Error HOT 4
- Bug: [Error] Call to undefined method Config\Mimes::__set_state() at ROOTPATH/writable/cache/FactoriesCache_config HOT 7
- Bug: [DebugBar] Flush a session flash-data when redirect by "Refresh" method HOT 2
- Add required_if validation rules
- Bug: Entity Standalone Class initialization error HOT 2
- Bug: How can I know which browser name is the request from?
- Bug: How can I know which browser name is the request from? HOT 14
- Bug: storing validation rules in Config/Validation causes error HOT 1
- Bug: Fatal error: Uncaught Error: Undefined constant "ENVIRONMENT" in /var/www/html/MyApp/system/Common.php:777 HOT 1
- Bug: cannot run PHPUnit testing in CI 4.5.1 appstarter HOT 5
- "Deploy API Documentation" fails HOT 1
- Composer PSR-4 notices "does not comply with psr-4 autoloading standard" HOT 16
- Bug: CodeIgniter\Router\RouteCollection::getRoutesOptions(): Argument #1 ($from) must be of type ?string, int given, called in system\Router\DefinedRouteCollector.php on line 49 HOT 3
- Bug: `migrate:rollback -b` impossible due to TypeError HOT 4
- Bug: [Validation] if_exist is not working as intended with arrays HOT 1
- Bug: spark routes doesn't work with `(.+)` HOT 2
- Bug: nested $routes->group() with same filter name doesn't work as exepcted HOT 14
- Bug: system/Database/OCI8/Connection.php fails to parse valid DSN HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from codeigniter4.