How is K2 image information stored? - joomla

We have imported the old Joomla content into K2. In the original content the article image was simply placed inline using the html editor, but although the images do show up, they don't look at all like those handled by K2 using the tab image > browse server. K2 images looks much better.
Since we have about 1000 articles I would like to make a script that can convert the images to the "K2 way". My main problem here is that I can't figure out how K2 stores this image information. I have tried comparing two mysql dumps, before and after adding an image, but I have not been able to determine which tables are involved.
So my question is: How and where is K2 article image informartion handled?
Of course, if there already exists a solution that can do this kind of conversion, I would like to know that as well.

Even after logging and analyzing all SQL queries I still can't find where in the DB K2 image info is stored. And there is a reason why: It doesn't use the DB at all.
Images are stored in
/media/k2/items/cache/
/media/k2/items/src/
using the md5 sum of the K2 item ID as the base of the filename. It then looks on the fly for images in these folders to display when you browse the articles.
There is a bit more info here:
Where does k2 componet store its images in the database?
I have now made a script that will convert embedded images to K2 external images.

Easily way to get original image instead of resized for K2 item, for example:
$image=str_replace("cache","src",$item->image);
$image=str_replace(array("_XS","_S","_M","_L","_XL"),"",$image);

Related

Where does k2 component store its images in the database?

I want to retrieve/query images stored by joomla k2 component (under the Image Tab).
To display the K2 item image you can use this
echo "media/k2/items/cache/".md5("Image".K2 ITEM ID HERE)."_XL.jpg";
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!
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
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.

ASP.Net MVC. Making Dynamic Images SEO Friendly

I have a website made to provide free web-based tools for making indie games. Currently, it only supports artists contributing to games. The features for helping artists consist of a set of artist community tools that allow artists to upload images based on a description, then we post that image in a gallery page. Other artists can upload their images and each image can have several revisions.
The way I chose to implement the image upload and display feature is by serializing uploaded images to a byte array and storing it in the database. When I need to display the image in the UI I just call a controller action I named "GetScaledGalleryImage" and pass in the image ID. That controller action takes the binary from the database and converts it back into an image, returning the requested image back.
This works very well functionally, but the problem I realized later is that the google crawler thinks all of my images are named "GetScaledGalleryImage" so if someone searches for "sylph" on google images, nothing comes up from my site, but if someone searches for site:watermintstudios.com getscaledgalleryimage, all of my images come up.
Here is an example of the URL that is being output in my HTML http://watermintstudios.com/EarnAMint/GetScaledMedia/68?scale=128
In the past, pre-MVC I would handle 404 errors and return content based on what was requested even if the page didn't actually exist. This would of course allow me to have the images pulled back by the image name (or description).
Is that the best way to do this? Or is there a better option? Something simpler would be better like if I could just do http://watermintstudios.com/EarnAMint/GetScaledMedia/Iris%20Doll?id=68&scale=128, but based on how google indexes images, would that give me what I need? Or do I need to provide image file extensions for maximum indexability?
Thanks all
It is important when doing Search Engine Optimization to always use alt="this is a crazy robot" for your images. This will help the crawler identify them. Note: always use alt, don't always name your images this is a crazy robot.

Thumbnail different from actual image

Here is a scenerio, on my products page I want to add an image of the product dimensions but for this image I want to use thumbnail which is different from the actual image which will say Dimensions. This will be applied to all the products across the store. So there will be one thumnail image for all the products that will be associated with it’s dimensional image. I want to show it on the gallery page as last image.
Any help would be greatly appreciated.
Regards,
Avian
If I'm understanding you correctly, you just want every product to have a thumbnail that can be set to be one of several images.
You will need to create a custom attribute for your products, and then programmatically set your current inventory to your defaults. (Or manually change them) There is a knowledgebase article that will assist you with custom options (if applicable), or another article I found via Google to assist in custom attributes.
It's likely not the best way of doing it, but an example of the JavaScript method I was talking about is simply to add the following into a JS file on your server.
document.observe("dom:loaded", function() {
$$('.catalog-product-view .image-thumb:last img').each(function(item){item.src = 'http://domain.com/path/to/image.jpg'});
}

SEO for Dynamically Loaded Images

I have a developed PHP code to dynamically load files contained in a directory into a gallery / slideshow. I have many (40 - 50) of these gallery web pages which display images grouped by content. With hundreds of images, the dynamic gallery code allows me to add images to a directory without having to write code to each web page each time.
However I've realized that these files will be invisible to search engines since there isn't any HTML code to index on (e.g. the 'alt' tag). Does anyone have any suggestions on how to get these images indexed? Two ideas I've had:
1) Write a program to automatically generate a single web page for every jpeg file which will display the image when found with the search engine and contain a link to the gallery page where the user can see more content. The benefit to this method is not having to modify my live web pages. The downside is hundreds of additional files only to be found by a search engine.
2) Write a program to generate hidden links that can be pasted into my gallery html page - using the alt tag. The benefit to this method is that users would find my main gallery page with a search. The downside is having to cut and paste code to my live gallery web pages - defeating somewhat the purpose of a dynamic gallery.
I'm new at this, so any suggestions would be appreciated.
If I understand you correctly:
I would have one page that just lists thumbnails of pages, and then one page for each of the images, that shows a bigger version of each image, and all the meta-data you have. The best would be if you added a short unique snippet of text to each image, describing what in it.

any tutorials/blogs regarding uploading more than one db images

I have exhausting goggle looking for a way to upload more than one db images.
I had a look at
http://www.mikesdotnetting.com/Article/125/ASP.NET-MVC-Uploading-and-Downloading-Files or http://mattias-jakobsson.net/post/2009/11/19/Handling-image-uploads-with-AspNet-Mvc.aspx or http://www.johnpscott.co.uk/devnotes/picpick/default.aspx or http://rusanu.com/2010/12/28/download-and-upload-images-from-sql-server-with-asp-net-mvc/ and so on. I no luck.
Does anyone has a tutorial or recommend a book that demostrate how to upload more than one db images. I am using vs 2010, asp.net mvc3 in C# with SQL Server 2008R2. All I am trying to do is to have couple db images for each product.
Thanks
The first link you provided is a good start for what you need.
Store all images for a product change....
It shows how to upload multiple files. From this you could modify the table where the images are inserted to add a key for the record relation back to your product.
Retrieve all images for a product change...
To pull them back from the database you would call the code in the same article (GetFile), modifying the select statement to include your product key INSTEAD of the ID of the individual image.
Display all images for a product change...
This is where it changes quite a bit. The author of the first article still returns one file as a FileContentResult. Obviously, this won't work for your situation.
Have a look at this article. It uses an XML file to load up multiple images BUT you would replace this code with the code in GetFiles to create the Image List. It shows how to create a controller, model and view for this. You could create a partial view to have the images on the same page as the product view.
This sample shows how to get an image list out of the DB into a view. (To help with modifying GetFiles to better work for this...)

Resources