17
votes
Accepted
Image asset url is not being output
So after looking through other craft websites to see how they where able to get images to work I discovered what I did wrong when setting up the asset source. The thing is though that the craft ...
12
votes
Image alignment and size in Redactor 2
No need for a plugin.
Just add:
"imageResizable": true,
"imagePosition": true,
to your chosen redactor config file i.e. (/craft/config/redactor/standard.json)
11
votes
Accepted
Looping through images in a Asset field type
An Asset field – like all relational fields, including Entries, Categories etc – always return an array-like object which is an instance of a class called ElementCriteriaModel. To output the actual ...
8
votes
Is there a way to create a "sticky" asset
Based on adding a lightswicht ("sticky") as suggested by @carlcs I think you should be able to solve this by just using two order fields.
{% set images = craft.assets.folderId(18).order('sticky desc, ...
8
votes
Accepted
Using Image Transform as another custom field
The imageTransform value is actually an object, representing the entire dropdown field.
Update the first line to this...
{% set imageTransform = storyEntry.storyThumbnailTransform.value %}
This ...
7
votes
How can I automatically generate responsive images from a single hi-res asset?
There is a great article here which I thoroughly recommend reading. It goes into this in great detail.
It even includes a twig macro that deals with both retina images as well as responsive images:
...
7
votes
Output image in template
When you are working with an asset field you are actually looking at the object so you need to call {{asset.url}} in order to actually output the path to the image or whatever asset you are working ...
7
votes
Accepted
Craft 3 image asset getUrl() not showing
The solution is to enable "assets for this source have public URLs" in the volume settings.
6
votes
Accepted
Load an asset at random each page load
Simply using 'RAND()' in the order parameter does the trick.
{% for image in entry.banner.limit(1).order('RAND()') %}
{{ image.url }}
{% endfor %}
5
votes
Accepted
Is there a way to create a "sticky" asset
Add a lightswitch field to your assets and query for assets with the lightswitch enabled first. Use the ids() method to get just the assets' IDs and merge them with the rest of your assets' IDs to ...
5
votes
Accepted
Global Image Variables?
seo.twittercard is an ElementCriteriaModel. To access the actual asset, you need to use seo.twittercard.first (or equivalently: seo.twittercard.first()).
However, you should always check that this ...
5
votes
Accepted
Importing images from external url and saving to entry using plugin
Here's how I did it in a recent project:
$fileIds = array();
// get remote image and store in temp path
$imageInfo = pathinfo($data['image_url']);
$tempPath = CRAFT_STORAGE_PATH . '...
5
votes
Upload any size image into carousel
You shouldn't need to create a custom plugin to do that.
You can easily create a Matrix content field for your carousel. Create a new block called slide. From there you can create an asset field to ...
5
votes
Accepted
Is it possible to create a new asset from an image URL?
Download the image into a temp file, then upload it as an asset. You can find $iAssetSourceId by looking at the URL when editing an asset source
$iAssetSourceId = 4;
$iAssetFolderId = (int)craft()-&...
5
votes
I am unable to correctly return the url of an uploaded asset
I found the answer in a similar post here: Image asset url is not being output
My problem was with my Asset Source settings. Now that I think about it, it's obvious: I had no public URL declared for ...
5
votes
Accepted
Images containing EXIF orientation tag are not rotated on upload
After some mail exchanges with Brad and Andris from Craft CMS, it turned out that there is an edge case where the image rotation on upload will not work if the EXIF extension is not installed (which ...
4
votes
Accepted
Images lose quality when I upload to Craft
There is a way to get Craft uploading my pixel-perfect images without re-save them?
You can upload via FTP and then run the Update Asset Indexes tool from the Settings page in the control panel.
If ...
4
votes
Load an asset at random each page load
I wanted to see if the same thing could be accomplished using Craft's shuffle function. At first, I was looping through the image array and using an if statement to grab the first one:
{% for image ...
4
votes
Is there any way to prevent Craft from doing anything with uploaded GIF assets?
When you upload an image to Craft, the image is automatically “cleansed” using the same basic process that Craft uses to create image transforms. That happens to ensure that there are no malicious ...
4
votes
Accepted
Getting image for product in Cart Screen
This actually depends where the image is stored - if the asset (image) field is on the product, and is called myImage, then as per Brad's example you'd use:
lineitem.purchasable.product.myImage
......
4
votes
Redactor image caption not saved and formatting lost
I copied your Redactor settings to a clean installation of Craft (2.6.2945) and added an image to a Rich Text field set to use those specific settings. Initially I encountered the same behaviour. ...
4
votes
Adding images directly to public folder
You need to use the Update Asset Indexes tool in Settings in the control panel:
Whenever there are files within your asset source that were not added directly by Craft (e.g. via FTP), you will need ...
4
votes
404 Error showing for Asset Images
Figured it out. I assumed that my assets folder needed 744 just as the install instructions mentioned for the Craft CMS folders. But, I need to change the permissions to the standard 755. Once I did, ...
4
votes
Using Focuspoint with eager loading
After some research I found out that this problem has no simple solution (unfortunately). Check https://github.com/smcyr/Craft-FocusPoint/issues/10.
A solution would be not to use eager loading (...
4
votes
Accepted
Craft 3 Image quality is terrible after asset upload from admin panel
Converting my comment(s) into an answer...
Make sure you are using the ImageMagick library to handle image manipulation (instead of the default GD library). It provides much better results.
Craft ...
4
votes
How do I add Alt Image Tags to my photos?
Out of the box, you can use the image "Title" as alt text. Since it is already configured - you don't need to add any additional fields. Then you can output this in your twig template as:
{% set ...
3
votes
How to add dynamic watermarks to images in Craft/Twig
You'd definitely need a plugin for this. Craft's native abilities don't cover watermarks.
I've never attempted it myself, so these are just "best guesses"... but give the following plugins a shot:
...
3
votes
Global Image Variables?
This is a general structure to display global images in any template:
<img src="{{ globalHandle.globalAssetHandle.one().getUrl }}" alt="">
You have to set your global handle ...
3
votes
403 Forbidden Assets
This article will help you set permissions properly for Craft CMS installs:
Hardening Craft CMS Permissions
It leverages Craft-Scripts to do the heavy lifting.
3
votes
Image Transforms - Image not processed until second page refresh
I'm having this problem too. This can't be expected behaviour, can it?
EDIT (SOLVED):
I've learned from MildlyGeeky in the Craft Discord server that this issue is caused by Twig being picky about ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
image × 198assets × 76
image-transforms × 37
templating × 23
upload × 21
craft3 × 17
redactor × 14
richtext × 10
plugin-development × 9
matrix × 9
url × 7
entry × 6
field × 6
entries × 5
error-message × 4
loop × 4
responsive-images × 4
plugin-craftcommerce × 3
plugins × 3
php × 3
error × 3
import × 3
404 × 3
eager-loading × 3
assets-field × 3