- Posts: 55
COMMUNITY FORUM
K2 image handling
- WinniePooh
-
Topic Author
- Offline
- Senior Member
Less
More
10 years 7 months ago #131671
by WinniePooh
K2 image handling was created by WinniePooh
Hello everyone,
I've some questions about the handling of images in K2. How do I reuse images in K2? I would like to use the /images directory where my old images are stored, but K2 uses the /media folder. Also I can't look through hundreds or thousands images, because the image names (which I've renamed properly before) have names like 002e8e491b09a55f1bac8b9f7f969c26.jpg. My authors are now handling it so, that they are uploading an image everytime they create an article. After a couple weeks I've some images about 10 times stored in the /media folder and the whole Joomla installation size is increasing every week about 20mb!
Even when I upload an image through JCE in the /image directory, K2 creates everytime a new copy in the /cache directory when the same image is used.
I'm running a news website where I'm dependent of reusing images. I need a smart solution for my authors, so they don't need to store the main images on their computers and upload it every time.
Maybe someone has done the same experience and has found a solution for this.
Regards
I've some questions about the handling of images in K2. How do I reuse images in K2? I would like to use the /images directory where my old images are stored, but K2 uses the /media folder. Also I can't look through hundreds or thousands images, because the image names (which I've renamed properly before) have names like 002e8e491b09a55f1bac8b9f7f969c26.jpg. My authors are now handling it so, that they are uploading an image everytime they create an article. After a couple weeks I've some images about 10 times stored in the /media folder and the whole Joomla installation size is increasing every week about 20mb!
Even when I upload an image through JCE in the /image directory, K2 creates everytime a new copy in the /cache directory when the same image is used.
I'm running a news website where I'm dependent of reusing images. I need a smart solution for my authors, so they don't need to store the main images on their computers and upload it every time.
Maybe someone has done the same experience and has found a solution for this.
Regards
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
10 years 7 months ago #131672
by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: K2 image handling
You can use an extrafield (or two for the smaller image) with a conditional term.
If that image extrafield exists then do not use the K2 image. If it doesn't then you should use the K2 image. Upload your library at the /images folder so the users can choose their images.
If that image extrafield exists then do not use the K2 image. If it doesn't then you should use the K2 image. Upload your library at the /images folder so the users can choose their images.
Please Log in or Create an account to join the conversation.
- WinniePooh
-
Topic Author
- Offline
- Senior Member
Less
More
- Posts: 55
10 years 7 months ago #131673
by WinniePooh
Replied by WinniePooh on topic Re: K2 image handling
Thank you for your answer. But I've no idea what I need to do :) Do I use the K2 extra field as a dummy where I can choose between K2 images and normal images? Or do you mean to add a custom field in the backend? And where do I choose a specific image?
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
10 years 7 months ago #131674
by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: K2 image handling
This will require custom coding but it will not be anything extravagant.
You need to add two more extrafields. One for small images and one for large.
In your template where you are rendering your K2 image (in all views category_item, tag, item etc) perform a check.
If the extrafields exist show it else show K2's default image.
Then control that image with CSS or use the same markup as K2's image so it will look identical in your template.
The same code will have to be ported to K2 Content modules as well.
You need to add two more extrafields. One for small images and one for large.
In your template where you are rendering your K2 image (in all views category_item, tag, item etc) perform a check.
If the extrafields exist show it else show K2's default image.
Then control that image with CSS or use the same markup as K2's image so it will look identical in your template.
The same code will have to be ported to K2 Content modules as well.
Please Log in or Create an account to join the conversation.
- WinniePooh
-
Topic Author
- Offline
- Senior Member
Less
More
- Posts: 55
10 years 7 months ago #131675
by WinniePooh
Replied by WinniePooh on topic Re: K2 image handling
Will the extra field not displayed in the articles of the category? I've some programming experience but I can't imagine how the check should look.
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
10 years 7 months ago #131676
by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: K2 image handling
It would be a simple if else statent.
If the extrafield is both set and has a value then display that.
Else display K2's image.
This check should be a global thing and it should present in all your template files.
If the extrafield is both set and has a value then display that.
Else display K2's image.
This check should be a global thing and it should present in all your template files.
Please Log in or Create an account to join the conversation.
- WinniePooh
-
Topic Author
- Offline
- Senior Member
Less
More
- Posts: 55
10 years 1 month ago #142622
by WinniePooh
Replied by WinniePooh on topic K2 image handling
Hi again,
after a couple of months I would like to devote again to the problem :)
Here is what I've written in the item.php:This works in the item view.
On the home page I'm using the small images and I tried to edit the category_primary.php. When I use "<?php print_r($this->item->extraFields); ?>" I get a weird String like this: [{"id":"1","value":"\/images\/busquets_vertragsverl%C3%A4ngerung.JPG"}].
How can I extract the image source? And the bigger question: How can I resize the image efficient without having to copies of the same image?
Regards and many thanks for the previous help
after a couple of months I would like to devote again to the problem :)
Here is what I've written in the item.php:
<?php if(file_exists($this->item->image)) { ?>
<img src="<?php echo $this->item->image; ?>" alt="<?php if(!empty($this->item->image_caption)) echo K2HelperUtilities::cleanHtml($this->item->image_caption); else echo K2HelperUtilities::cleanHtml($this->item->title); ?>" style="width:<?php echo $this->item->imageWidth; ?>px; height:auto;" />
<?php } else { ?>
<?php echo $this->item->extraFields->Images->value; ?>
<?php } ?>
On the home page I'm using the small images and I tried to edit the category_primary.php. When I use "<?php print_r($this->item->extraFields); ?>" I get a weird String like this: [{"id":"1","value":"\/images\/busquets_vertragsverl%C3%A4ngerung.JPG"}].
How can I extract the image source? And the bigger question: How can I resize the image efficient without having to copies of the same image?
Regards and many thanks for the previous help
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
10 years 1 month ago #142689
by Krikor Boghossian
Replied by Krikor Boghossian on topic K2 image handling
Unfortunately if you use this method, you cannot resize the images.
what does <?php echo $this->item->extraFields->ALIAS->value; ?> produce?
Also this post might come in handy.
www.joomlaworks.net/forum/k2-en/40669-solved-custom-alt-text-in-extra-field-images#142067
what does <?php echo $this->item->extraFields->ALIAS->value; ?> produce?
Also this post might come in handy.
www.joomlaworks.net/forum/k2-en/40669-solved-custom-alt-text-in-extra-field-images#142067
Please Log in or Create an account to join the conversation.
- WinniePooh
-
Topic Author
- Offline
- Senior Member
Less
More
- Posts: 55
10 years 1 month ago #142718
by WinniePooh
Replied by WinniePooh on topic K2 image handling
When I use <?php echo $this->item->extraFields->Images->value; ?> OR <?php echo $this->item->extra_fields->Images->value; ?>, I get no output. I dont't know why it works fine in the item.php but not in the category_primary.php.
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
10 years 1 month ago #142720
by Krikor Boghossian
Replied by Krikor Boghossian on topic K2 image handling
Have made sure that all the extrafield related settings are set to "Show" in the category's setttings.
Furthermore the category_primary.php file is not a part of the stock K2 template.
I think you should also ask the template's developer about this issue.
Furthermore the category_primary.php file is not a part of the stock K2 template.
I think you should also ask the template's developer about this issue.
Please Log in or Create an account to join the conversation.
- WinniePooh
-
Topic Author
- Offline
- Senior Member
Less
More
- Posts: 55
10 years 1 month ago #142722
by WinniePooh
Replied by WinniePooh on topic K2 image handling
I forgot the category settings... Now it works great :) Thank you Krikor.
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
10 years 1 month ago #142750
by Krikor Boghossian
Replied by Krikor Boghossian on topic K2 image handling
You 're welcome :)
Please Log in or Create an account to join the conversation.