I want to retrieve/query images stored by joomla k2 component (under the Image Tab).
4 Answers
To display the K2 item image you can use this
echo "media/k2/items/cache/".md5("Image".K2 ITEM ID HERE)."_XL.jpg";
-
2Not everybody is a programmer or know about databases and phpMyAdmin. You should / could explain where this line could be put. – Yannis Dran Jan 19 '15 at 18:55
-
For anyone not using PHP it's basically `md5("Image1212")` where 1212 is the ID of the K2 item. Remember capital `I` in Image. – robino16 Jan 30 '23 at 21:39
It's not stored in the database at all.
They use the md5 hash on the actual K2 item ID, and that is how they rename and save the image in the folder media/k2/items/cache/
.
Anywhere the K2 item is pulled up, they use JFile::exists
(which is used to check if a file exists in the path set) with the path
URL-ROOT."media/k2/items/cache/".md5("image" . K2 ITEM ID HERE)."_XL.jpg"
and if the file is there, it shows the image.
Also, the _XL.jpg
will change depending on what size the image is set to display on the page, be it a thumbnail, large, XL, etc.
I know that isn't what you wanted to hear, but that is how they do it :) Hope that helps man!

- 99,765
- 32
- 217
- 249

- 712
- 5
- 19
-
Thank you Caleb, actually i was looking at this file modules/mod_k2_content/helper.php and show how images were displayed and surely you have clarified it for me. Cheers – mukamaivan Jun 10 '12 at 17:43
-
5This solution was slightly wrong. The md5 function needs to have "Image" before the K2 Item ID like it is in surya's answer. So it should be: URL-ROOT."media/k2/items/cache/".md5('Image'.K2 ITEM ID HERE)."_XL.jpg" – David Stinemetze Nov 25 '12 at 22:07
Though you got the answer sharing the info may be helpful:
If working within the K2 Templates (Html overrides) following can be used to access the image added via K2 image tab.
$this->item->image
OR
$this->item->imageXLarge (size you want)
you get relative url : /media/k2/items/cache/29642a1d30cebf98734fb424b2b1316b_L.jpg

- 19,758
- 10
- 59
- 100

- 373
- 3
- 9
You can find the originals in the media/k2/items/src/ directory. Also, @David is correct, "Image" is needed as prefix to the k2 item id.

- 1,045
- 4
- 14
- 30