Keyword

How is an image appended to an item

  • cemmac
  • cemmac's Avatar Topic Author
  • Offline
  • New Member
More
14 years 5 days ago #88556 by cemmac
How is an image appended to an item was created by cemmac
Hi All,
First off excellent component and is suiting most of my needs.

Here is what i would like to know if its possible....
I have a new client that wishes to add date events into a calendar and then publishing on the front page and other pages....this is not an issue as i have inserted new fields into JCAL Pro.

Now comes the main issue...if i insert a new item into a cat that has been pre defined using a trigger from the jcal to insert the info into said new item....how can i attach the image to the new item in K2 ?

How is the image linked to the item in K2 normally as i cannot see anything in the k2_item table for the image ?

Really what i would like to know is how is the image linked to an item in K2 ? this would then make my task a little easier....I hope :-)

I know that this is a strange request but the display methods of K2 are amazing and very simple to implement on any page.

Thanks in advance
cemmac

Please Log in or Create an account to join the conversation.

More
14 years 5 days ago #88557 by william white
Replied by william white on topic How is an image appended to an item
First off, this is not New To K2!
K2 uses md5 hashes to keep up with the item images. It creates several images and keeps them in media/k2...something or another.
There are fields for image_caption and image_credits in the items table
Im not sure what the md5 is generated on but you should be able to find it by tracing the standard code that adds items in the core.
Also, check the k2 import tool by arthur newman, im not sure if it does the images or not, but it may be there

Please Log in or Create an account to join the conversation.

More
14 years 5 days ago #88558 by David R.
Replied by David R. on topic How is an image appended to an item
I can't speak to the gallery because it's an addon that I don't use, although from what I can see, it's a similar mechanism. It may have a database component to it, because I saw reference in the code to the k2_items.gallery column, but as far as a single attached image, you are right that the database is not used.

When you attach an image to an item, the image gets stored on disk at:

/media/k2/items/src

K2 Then renders 6 versions of the original, appending _Generic, _XS, _S, _M, _L, and _XL to the original file name. These versions are used depending on the configuration of the category.

The rendered versions all get stored in:

/media/k2/items/cache

And they always are converted/assumed to be .jpg, no matter the source of the original.

The file name of the stored file is generated via md5("Image".$item->id).

So if you wanted to do a manual bypass, assuming you have the k2_items.id column, you could simply call the same function, and stick the same files into the directories in question.

If you want to look at the code in question look at the save() method for the item class you find in:

/administrator/components/com_k2/models/item.php.

You should be able to easily find the images code that generates all the converted versions. If you know enough PHP Oop, i assume you could include the model file, load the data, and call the save method, but in a quick glance you're probably better off just copying the needed code, because it looks like it assume that there's an upload involved, and if you're simply copying files around, there's no discrete method call you can make to just get a piece of the save method.

Please Log in or Create an account to join the conversation.

  • cemmac
  • cemmac's Avatar Topic Author
  • Offline
  • New Member
More
14 years 5 days ago #88559 by cemmac
Replied by cemmac on topic How is an image appended to an item
David R. said:I can't speak to the gallery because it's an addon that I don't use, although from what I can see, it's a similar mechanism. It may have a database component to it, because I saw reference in the code to the k2_items.gallery column, but as far as a single attached image, you are right that the database is not used.
When you attach an image to an item, the image gets stored on disk at:

/media/k2/items/src

K2 Then renders 6 versions of the original, appending _Generic, _XS, _S, _M, _L, and _XL to the original file name. These versions are used depending on the configuration of the category.

The rendered versions all get stored in:

/media/k2/items/cache

And they always are converted/assumed to be .jpg, no matter the source of the original.

The file name of the stored file is generated via md5("Image".$item->id).

So if you wanted to do a manual bypass, assuming you have the k2_items.id column, you could simply call the same function, and stick the same files into the directories in question.

If you want to look at the code in question look at the save() method for the item class you find in:

/administrator/components/com_k2/models/item.php.

You should be able to easily find the images code that generates all the converted versions. If you know enough PHP Oop, i assume you could include the model file, load the data, and call the save method, but in a quick glance you're probably better off just copying the needed code, because it looks like it assume that there's an upload involved, and if you're simply copying files around, there's no discrete method call you can make to just get a piece of the save method.


Thanks very much David,

I will give it a try and see what happens.

It should be simple enough to use the same code for the images and thentransfer all.

i will keep you guys up to date on this.

Again thanks

Cemmac

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum