Hello I'm using backpack which uses elfinder as a file manager, and i want to achive te following:
when an image is uploaded I want to create 3 copies of it
one with it real dimension
the second is 200x200
and the third 50x50
Note: Like WordPress which has this mechanism built in (uploading multiple sizes of the image)
Unfortunately, there's no easy way to do that thanks to elFinder itself. The PHP package for elFinder doesn't have events or anything like that, for you to customize its upload behaviour. And doing it in Javascript would probably not be a good idea.
But thanks to Backpack, there's one thing you could do, that could be useful. You can use Model Events inside your CrudControllers, to do stuff after the cretate/update form has been submitted. For example:
when the updated event happens, check if that file that was upload (with real dimensions) has thumbnails; if so, do nothing;
if not, create the thumbnails using a library like Intervention image that is already included in Backpack;
So it would looks something like this:
public function setup()
{
// ...
Product::saved(function($entry) {
if (!$entry->hasThumbnailsForAttachment()) {
$entry->generateThumbnailsForAttachment()
}
});
}
Then in your Model you could create these two methods, hasThumbnailsForAttachment() and generateThumbnailsForAttachment().
Hope it helps!
Related
I have an app with several Vue.js components. I'd like to display a few image assets inside one of them with the equivalent functionality of a helper function Cdn::asset()
Is there an easy or efficient way to do this? Currently I display all assets this way, because I have a Cdn::asset() helper that provides the correct filepath according to .env configuration.
For media files from the application it isn't a problem to just output the path to the image, but with image assets involved in the design of the site is there a worthwhile way to do this?
Only thing I can think of is outputting a base path from Laravel into Vue based on the Cdn::asset() function.
As soon as I wrote that out, it came to me. Just the following function in the head of the document
<script>
function asset(file) {
return '{{Cdn::asset('')}}' + file;
}
</script>
I use Orchard cms. I want when images uploaded, the images get watermark automatically. How can I do this?
To add watermark automatically, you have to add a OnPublished handler for ImagePart as following:
OnPublished<ImagePart>((context, part) => {
var mediaPart = part.As<MediaPart>();
// Here you can add watermark code
});
If you want to add the watermark on the original uploaded image, you have to call it from the handler directly, but if you want to use media processing module mechanism (Which will keep the original image as is, and create a new one with filters applied and save it in _Profiles folder), then you can add a new implementation for IImageFilterProviderto add a new filter for Orchard media processing pipeline.
Finally, I recommend you to use ImageResizer.Plugins.Watermark plugin to achieve this, because Orchard already use ImageResizer component as default image processing framework.
Update: Please refer to this link for complete implementation, or this repo for source code.
This should be possible by providing a custom implementation of IImageFilterProvider. Search for this interface in the solution, you will find a ResizeFilter and FormatFilter in the Orchard.MediaProcessing module as an example.
Also, there are some articles like http://www.davidhayden.me/blog/developing-custom-image-filters-in-orchard-cms.
I'm trying to load all images in the product page , but i don't want to resize them.
Does anybody know a simple solution tot do that?
The opencart version is 2.1.0.2
In-order to retrieve images without being re-sized on the product page, you need not re-size the images in the product controller file.
So in the Product Controller File, locate that in /catalog/controller/product/product.php
In the public function index()
Look out for $this->model_tool_image->resize remove the function call and use the link to the image instead to return to the template HTTPS_SERVER . 'image/'. $image_variable provided HTTPS_SERVER is defined in /config.php
Note: $image_variable could be $product_info['image'] or $result['image'] , use your best judgement.
Tip: Use vqmod as you would be modifying the core controller file
In order to use vQmod (according to the process described previously), you can take a look to this method for working with real images instead of thumbnails.
Note that there are other possible suggestions, such as:
OCmod which can be found here
Image Autosize extension which can be found here
I have aroung 6k posts with images and now I need to link all them to the source image (to open them with pretty photo and make them "responsive") there are no custom fields with src links, simply html code with src.
Any suggestion in how to do it?
Thanks in advance!
You could use a javascript code that you embed in your template. This code looks for all images in the post content and modifies them as wanted. With jQuery something like that:
$("img").attr("src", function() {
return "/resources/" + this.title;
});
- taken from the jQuery Docs
The down-side of that is that this script has to run everytime the post is requested again. The alternative option would be to write a php script to replace all links in the database once. That is probably more effort at first but in my opinion worth it since its a one time job.
Does there exist anything akin "UberSelectionWidget for images?" I'd like to get rid of direct-upload image fields and make all images to be managed through an image bank folder.
1) In all use cases upload image to image-bank folder first
2) Pick image from the folder by using some sort of image friendly selection widget (both Archetypes, Dexterity)
This way adding images would be unified within TinyMCE editor and news content items.
The problem, however, is that I cannot find any examples for reference picker for images solution.
Please see also Making TinyMCE image pick dialog point to a default folder on Plone
I am willing to replace News Item with my own content type just to get around this problem.
This product helped me in a Plone 3 project:
http://plone.org/products/upload-reference-widget
I had to customize it a little but I think it's a good base to start with.
No Dexterity support IIRC.
Use ReferenceField instead of ImageField in your content types, it make the job done.
You can extend 'News Item' type by using schemaextender.
Bonus:
But asking for people to first add image before adding a news is weird. As widget you must use uploadreference widgets for archetypes as mentionned by marcosfromero . It works and let you add an images without going away of your addform.
I'm not sure but there is no z3cform widget at the moment to achieve this (upload & create ref), may be someone can create it or get me wrong ?