In the Laravel 5, drunk all around. What I want to do is to shape shapes (size and crop) and use interference to cache the images.
.
I started using it as an example:
/ / Routes.php path :: find ('imager / {Src}} ', function ($ src) {$ cacheimage = Image :: cache (use function ($ image) ($ cc) {return $ image- & gt; ("files / image / source" source ) -> resize (100,50);}, 10, true); return reaction: create ($ cachestage, 200, array ('content-type' => image / JPEG '));} );
When I load an image like this:
// template & lt; Img src = "{{imager / image.jpg}}" />
This works fine.
But ... in my situation Images can be located in different (sub) directories, sometimes many levels are deep
Example:
- Files / images / Image.jpg
- IMG / Common / Logo.png
When such images are loaded:
// template & lt; img src = "{{" imager / files / images / image.jpg "}}" />
route no more work After all, Files , Images and images.jpg are all URL segments and the amount of them may be different
The image URL (bold) should be handled as a variable:
Root :: Receive ('imager / Files / Image / Image JPG ', function ($ src = false)
Then I should be able to pass the course size and harvesting parameters. Because the length of the IMG URL can be different I think I can pass parameters like? W = 100 & amp; H = 50 & amp; C = true or something else?
Update
When I use a query parameter for the image URL:
route :: get ('imager', function () {$ src = input :: get ('src', 1); $ cacheimage = Image :: cache (use function ($ image) ($ src) {return $ Image-> Make ($ Soric) -> Resize (100,100);}, 1, Falls); // One Minute Cash Expiry Return Response :: Make ($ Cachestage, 200, array ('Content-Type '= & Gt;' image / jpeg '));}); // template & lt; Img src = "{{" Imager? Src = Files / Images / Image Jpg "}}" />
This works
It's simple that you just want Laravel You must specify that your image parameter contains letters, slashes, dashes, underscores, and dots ( '[A-Za-z0-9 \ /. \ - \ _] +'
), because By default the framework matches everything, but slash /
.
Root :: find ('imager / {image}}', function ($ src) {$ CachedImage = Image :: cache (use function ($ image) ($ cc) {Return $ image-> Mac ($ src) -> Size (100,100);}, 1, Wrong); Return Answer: Creating ($ CachedImage, 200, ['Content-type' = & gt; 'Image / jpeg']);}) - & gt; Where ('image', '[A-Za-z0-9 \ /.. \' - _] ');
You can find more information about parameter binding.
No comments:
Post a Comment