-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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
Image Sizes #10181
Comments
This issues should close #4453 |
Initial go at the EDIT: Updated it to actually store so it's like: This allows use to really easily invalidate the images when the theme changes smth like imageSizes.forEach(size => deleteDirectory(imagesDirectory + '/' + size)) |
@JohnONolan I worked this weekend on the same feature. #10183 |
@notanengineercom Thanks! We'll definitely take a look. Image handling is sort of the third-rail of Ghost at the moment, so there's a lot of nuance to implementing this in a way which is broadly compatible for all users. Appreciate the PR either way though! |
Yes I'm aware and I agree that it has to be more compatible/flexible @JohnONolan. I just made the change to process the images on upload, and without changing the image ratio. I also changed some of the image processing in the image manipulator in lib/images/ (enabled cache for unix, changed the processing kernel and added imagemin which helps alot with the compression problem that sharp sometimes gives #10144). |
refs #10181 Adds support to request a size in the img_url helper using syntax like: <img src="{{img_url profile_image size="small"}}"/> Requires the image_sizes config to be defined in the themes package.json
refs #10181 * Added initial handleImageSizes middleware * Implemented saveRaw method on local file storage * Wired up handleImageSizes middleware * Implemented delete for LocalFileStorage * Removed delete method from theme Storage class * Deleted sizes directory when theme is activated * Ensured that smaller images are not enlarged * Renamed sizes -> size * Exited middleware as early as possible * Called getStorage as late as possible * Updated image sizes middleware to handle dimension paths * Revert "Deleted sizes directory when theme is activated" This reverts commit 9204dfcc73a6a79d597dbf23651817bcbfc59991. * Revert "Removed delete method from theme Storage class" This reverts commit b45fdb405a05faeaf4bd87e977c4ac64ff96b057. * Revert "Implemented delete for LocalFileStorage" This reverts commit a587cd6bae45b68a293b2d5cfd9b7705a29e7bfa. * Fixed typo Co-Authored-By: allouis <[email protected]> * Redirected to original image if no image_sizes config * Refactored redirection because rule of three * Updated comments * Added rubbish tests * Added @todo comment for handleImageSizes tests * Added safeResizeImage method to image manipulator * Used image manipulator lib in image_size middleware
Maybe Ghost Content API also needs size parameters. |
@allouis Can we close this issue? |
@kirrg001 Looks like " Validate image sizes in gscan" hasn't been completed - should we leave it open until that's done? |
I'd suggest to track this task in GScan as a separate issue, leave a comment here and close this one. If we track this in GScan separately, maybe we get some help/attraction from the community. |
Closing - the gscan issue can be tracked here TryGhost/gscan#173 |
On-the-fly generation fails if nginx is configured to directly serve images. Is there any other way to trigger the resizing? |
@luciandavidescu Unfortunately not, you could try adding a rule to nginx to forward |
@luciandavidescu the nginx |
Indeed, thanks, possibly nailed it with this:
Unfortunately, the resizing thing seems to no longer be working at all, for me at least, even after I turn these blocks off and restart ghost an nginx. For newly uploaded images, the helper |
@luciandavidescu Could you pls share the server (error) log? Do you have steps to reproduce for us? |
Below. Something that "sharp wasn't installed" apparently. Not sure if there's anything specific with my deployment to reproduce, just uploaded the image and expected it to show on the frontend, it did work with 2.10... Console: Ghost error log (domain ctrl-h'd to example.com): |
Sharp is an optional dependency. @allouis Could you please double check this report? If sharp was not installed, the image should just redirect to the original image? 🤔 |
Yeah it should, though it seems errors in ghost-ignition ignore the props passed to them, in favor of any error passed to them. So the error code was not correct. |
If I may, apparently there's an underlying issue with sharp as well - optional or not, it came by default with my 2.10 install (or maybe I just don't recall manually installing it, but it shouldn't matter either way), worked fine but was then dropped without warning on upgrade. Later edit: Indeed, it's no longer among the node_modules and I couldn't install it with |
refs TryGhost/Ghost#10415 refs TryGhost/Ghost#10181 refs TryGhost/Ghost#10421 When supplying a code to an ignition error, if you pass an error with a code, the error's code takes precedence rather than the explicit code you pass.
refs #10181 * Added initial handleImageSizes middleware * Implemented saveRaw method on local file storage * Wired up handleImageSizes middleware * Implemented delete for LocalFileStorage * Removed delete method from theme Storage class * Deleted sizes directory when theme is activated * Ensured that smaller images are not enlarged * Renamed sizes -> size * Exited middleware as early as possible * Called getStorage as late as possible * Updated image sizes middleware to handle dimension paths * Revert "Deleted sizes directory when theme is activated" This reverts commit 9204dfcc73a6a79d597dbf23651817bcbfc59991. * Revert "Removed delete method from theme Storage class" This reverts commit b45fdb405a05faeaf4bd87e977c4ac64ff96b057. * Revert "Implemented delete for LocalFileStorage" This reverts commit a587cd6bae45b68a293b2d5cfd9b7705a29e7bfa. * Fixed typo Co-Authored-By: allouis <[email protected]> * Redirected to original image if no image_sizes config * Refactored redirection because rule of three * Updated comments * Added rubbish tests * Added @todo comment for handleImageSizes tests * Added safeResizeImage method to image manipulator * Used image manipulator lib in image_size middleware
A couple of months ago we implemented basic image resizing and compression support with Sharp, the second half of the work that needed doing was supporting multiple image sizes in Ghost.
For example: You upload a 5,000px wide feature_image to a post.
post.hbs
✅index.hbs
There's already been a lot of discussion about this which has gone undocumented, so I'm going to summarise all the approaches and decisions I can remember.
In short, this will look like a very basic implementation of cloudinary fetch with a couple of transformation options.
Implementation Details
The theme determines the sizes it wants/needs to use based on its own layout design, and specifies those in its
package.json
. For example, in Casper we smaller thumbnails on the index page, eg demo.ghost.ioFor image sizes to be valid they must specify both width and height. Crop mode is optional and defaults to
fill
. Have no particular desire to replicate every cropping mode which sharp provides, nor any of the entropy based cropping.fill
=> sharpcover
fit
=> sharpcontain
Once sizes are specified, they can be passed as paramaters to the
img_url
helper in Ghost themes, eg:Once a request is made for an image, as long as a valid size is provided, then Ghost returns the image at the requested size and stores it for re-use in future. There is no spec for what this looks like, but I would guess that we would generate image files based on size names and store them alongside the master images. Eg.
file.jpg
file-small.jpg
file-medium.jpg
file-large.jpg
Questions
Unknown: How will this work with a headless front-end eg. Gatsby?
Tasks
img_url
helpergscan
The text was updated successfully, but these errors were encountered: