Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement core support for | resize(width, height, options) filter #5231

Merged
merged 36 commits into from
Aug 22, 2020
Merged
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
c3fbc13
wip dump on image resizing functionality
LukeTowers Aug 3, 2020
f56d1ee
Further work on the new resizing functionality
LukeTowers Aug 7, 2020
cdc45b0
Further WIP on resizer implementation, moving towards resizer object …
LukeTowers Aug 7, 2020
7b9408e
More WIP, moved logic in the appropriate locations
LukeTowers Aug 8, 2020
263ae87
More WIP on image resizer
LukeTowers Aug 9, 2020
6926908
required code from last commit
LukeTowers Aug 9, 2020
a992fb4
Support the resized URL as a route param instead of GET variable, ini…
LukeTowers Aug 9, 2020
b4dd255
Merge branch 'develop' into wip/image-resizing
LukeTowers Aug 9, 2020
9cb8a08
Finished implementing support for retrieving thumb URLs from FileMode…
LukeTowers Aug 13, 2020
17664dc
Reorganized the ImageResizer class
LukeTowers Aug 13, 2020
f54b167
Merge branch 'develop' into wip/image-resizing
LukeTowers Aug 13, 2020
04de6ef
Play nicer with tests
LukeTowers Aug 13, 2020
2351f21
Implemented resizing logic for File models, fixed bugs
LukeTowers Aug 14, 2020
064fc1f
Merge branch 'develop' into wip/image-resizing
bennothommo Aug 14, 2020
d52893d
Will need to use PluginTestCase for FileModel to be supported
bennothommo Aug 14, 2020
288918a
Finished initial implementation of resizer for all supported input im…
LukeTowers Aug 14, 2020
75e6633
Merge branch 'wip/image-resizing' of github.com:octobercms/october in…
LukeTowers Aug 14, 2020
545b899
Removed unnecessary design doc
LukeTowers Aug 14, 2020
ca386e2
tweak to default config for resized disk
LukeTowers Aug 14, 2020
f346312
Minor improvements
LukeTowers Aug 15, 2020
c25e41d
Remove unneeded use case
bennothommo Aug 17, 2020
096f5fd
Initial unit tests - WIP
bennothommo Aug 17, 2020
1fd9529
Add 'auto' height and width options
bennothommo Aug 17, 2020
0020809
Additional work on tests, should pass now
bennothommo Aug 17, 2020
aeae1bd
Remove trailing commas in commands
bennothommo Aug 17, 2020
5b5a15b
Ensure theme cache is rest to the "test" theme for ImageResizer
bennothommo Aug 17, 2020
05731b1
Fix bug
LukeTowers Aug 18, 2020
1f5350b
Test falsey width/height values
bennothommo Aug 19, 2020
b795ba6
Add URL sources tests
bennothommo Aug 19, 2020
3f58951
wip on imageWidth / imageHeight filter
LukeTowers Aug 19, 2020
444069d
Finished implement imageWidth & imageHeight filters
LukeTowers Aug 21, 2020
1e6573c
Cleaned up inline docs for ImageResizer, fixed tests
LukeTowers Aug 21, 2020
825075a
Fix support for Windows
LukeTowers Aug 21, 2020
a25567c
Use the same resizing process for FileModels that's used for everythi…
LukeTowers Aug 21, 2020
38718e0
Fixed bug where FileModel images wouldn't properly store their config…
LukeTowers Aug 21, 2020
779a879
Added support for new "image" column type that uses the ImageResizer …
LukeTowers Aug 21, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions modules/system/classes/ImageResizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -551,14 +551,14 @@ public static function normalizeImage($image)
// Process a string
} elseif (is_string($image)) {
// Parse the provided image path into a filesystem ready relative path
$relativePath = urldecode(parse_url($image, PHP_URL_PATH));
$relativePath = static::normalizePath(urldecode(parse_url($image, PHP_URL_PATH)));

// Loop through the sources available to the application to pull from
// to identify the source most likely to be holding the image
$resizeSources = static::getAvailableSources();
foreach ($resizeSources as $source => $details) {
// Normalize the source path
$sourcePath = urldecode(parse_url($details['path'], PHP_URL_PATH));
$sourcePath = static::normalizePath(urldecode(parse_url($details['path'], PHP_URL_PATH)));

// Identify if the current source is a match
if (starts_with($relativePath, $sourcePath)) {
Expand All @@ -577,7 +577,7 @@ public static function normalizeImage($image)
}

// Generate a path relative to the selected disk
$path = $details['folder'] . '/' . str_after($relativePath, $sourcePath . '/');
$path = static::normalizePath($details['folder']) . '/' . str_after($relativePath, $sourcePath . '/');

// Handle disks of type "system" (the local file system the application is running on)
if ($details['disk'] === 'system') {
Expand All @@ -586,7 +586,7 @@ public static function normalizeImage($image)
'root' => base_path(),
]);
// Regenerate the path relative to the newly defined "system" disk
$path = str_after($path, base_path() . '/');
$path = str_after($path, static::normalizePath(base_path()) . '/');
}

$disk = Storage::disk($details['disk']);
Expand Down Expand Up @@ -624,6 +624,21 @@ public static function normalizeImage($image)
return $data;
}

/**
* Normalize the provided path to Unix style directory seperators to ensure
* that path manipulation operations succeed regardless of environment
*
* NOTE: Can't use October\Rain\FileSystem\PathResolver because it prepends
* the current working directory to relative paths
*
* @param string $path
* @return string
*/
protected static function normalizePath($path)
bennothommo marked this conversation as resolved.
Show resolved Hide resolved
{
return str_replace('\\', '/', $path);
}

/**
* Check if the provided identifier looks like a valid identifier
*
Expand Down