By Mist on Tuesday, 20 January 2015
Posted in General Issues
Replies 6
Likes 0
Views 862
Votes 0
Hi guys, first of all i want to say that this task i think it's a little bit advanced and may be considered custom mod. i fully understand.

All i need is some general help pointing me to the right direction and if what i need involves just small code change and you guys don't mind to share the solution, i will be really happy, if not will have our programmer take a look at it.

So, let's begin ....

Currently EasyDiscuss lack a feature where we can define custom sizes for image attachments ("EasyBlog-Style" if you want )
By Default all attachments are uploaded into 2 sizes:
1. Original size
2. Thumb size

The thumb size is defined and controlled into this location
/administrator/components/com_easydiscuss/tables.php


by this line of code (around line 995 in the above file)
$image->resizeToFill( 160 , 120 );


Now, because we try to pull-off a new modern and fresh design for our discussions pages that goes way beyond the plain "old" list of topics we need to retrieve the first attachment of a post in a size s little bigger than default 160x120 configuration.

What i did, was this (and i think was the wrong approach)

I modified the above file "/administrator/components/com_easydiscuss/tables.php"
and setup the thumb size like this
$image->resizeToFill( 400 , 300 );


Now, all created thumbs will be at 400x300 size. This approach was wrong because ALL the attachment will have thumbs created at this size, thus generating performance speed problems for topics with a lot of images.

In our own designed layout, we retrieved the first attachment thumb file like this

1. First we queried the first attachment of the post

require_once( DISCUSS_HELPERS . DIRECTORY_SEPARATOR . 'helper.php' );
$db = DiscussHelper::getDBO();
$query = 'SELECT * FROM ' . $db->nameQuote( '#__discuss_attachments' ) . ' '
. 'WHERE ' . $db->nameQuote( 'uid' ) . '=' . $db->Quote( $post->id ) . ' '
. 'AND ' . $db->nameQuote( 'mime' ) . '=' . $db->Quote( 'image/jpeg' ) . ' '
. 'LIMIT 1';
$db->setQuery( $query );
$post_img = $db->loadObjectList();
$img_id = $post_img[0]->id;


2. Second we displayed the image file into our design, using the thumb size

<?php if ( $post_img ) {?>
<img width="100%" alt="<?php echo $post->title; ?>" data-src="/<?php echo JURI::root() . 'index.php?option=com_easydiscuss&controller=attachment&task=displayFile&tmpl=component&size=thumb&id=' . $img_id;?>" src="/<?php echo $this->baseurl ?>/assets/image/green.jpg" data-toggle="unveil" class="unveiled">
<?php } else { ?>
<img width="100%" alt="<?php echo $post->title; ?>" data-src="/<?php echo $this->baseurl ?>/assets/image/green.jpg" src="/<?php echo $this->baseurl ?>/assets/image/green.jpg" data-toggle="unveil" class="unveiled">
<?php } ?>


This approach, like i said before is wrong because all our thumbs will have 400x300 size, and we need ONLY the first one to have this size.

So, here comes my question.

1. How do you advice it's the best approach to have some "custom" attachment sizes implemented and displayed in our design ? (we need only the first attachment uploaded to have some different custom size)

Basically we will keep the default EasyDiscuss "thumb" size .. but let's say we will create only for first uploaded image attachment a custom "cover" size and retrieve this "cover" size for first attachment in our layout design like above.

2. Do you know any quick solution for this ?

3. Do you think that the best option is to create a joomla custom plugin that will "hardwire" into your attachment thumb creating process, without hacking the core post.php file ?

Hope i didn't eat too much from your time with this.
I need some general advice to pass to our programmer or, if this can be easy with just few lines of code implemented and are you willing to share it, i will be the happiest person on earth

Thanks guys !
Here the files.
·
Wednesday, 21 January 2015 11:25
·
0 Likes
·
0 Votes
·
0 Comments
·
Hello Mist,

Based on your requirement, I can conclude that you want to have only the first image has the size of 400x300. Is it correct? If so, since the $image->resizetofill is in for loop, why don't you do like this:

if ($i < 1) {
$image->resizeToFill( 400 , 300 );
} else {
$image->resizeToFill( 160 , 120 );
}


If the image is the first image ($i = 0), then resize it using the 400x300 size. Hope this helps.
·
Tuesday, 20 January 2015 23:25
·
0 Likes
·
0 Votes
·
0 Comments
·
OMG ..... that was it ? Sometimes i feel so stupid !
THANKS NIKKKKKKK !!!! That's what i needed, to define a custom size for the first attachment, everything else should be as default.

I assume that defining "custom" sizes for first attachment it's a little bit more advanced, right ?

Something like keep the default "thumb" size at 160x120 ... but defining 2 other sizes, let's call them "frontpage" and "cover"
1. "frontpage" at 400x300
2. "cover" at 1200x800
* actual sizes may vary, i just mentioned them for demo

In "list" topic pages i will call the "frontpage" size like this

 <img src="/<?php echo JURI::root() . 'index.php?option=com_easydiscuss&controller=attachment&task=displayFile&tmpl=component&size=frontpage&id=' . $img_id;?>" data-toggle="unveil" class="unveiled">


* notice that "&size=frontpage" from the image source

In topic detail page i will call the cover size like this
 <img src="/<?php echo JURI::root() . 'index.php?option=com_easydiscuss&controller=attachment&task=displayFile&tmpl=component&size=cover&id=' . $img_id;?>" data-toggle="unveil" class="unveiled">


* notice that "&size=cover" from the image source

.... all "thumb" size will work at the default settings of 160x120, i just need for first attachment, 2 other custom sizes to display them in various places in theme files.


Last think, i need to "re-process" existing attachmens according to new scenario, do you know any "magic" for this ?
If not, or if it's too complicated, that's ok ... i will edit them manually in photoshop and re-upload them

PS: I don't want to take advantage of your kindness. If you feel that what i am asking is too much, i understand.
Your first solution will work too for the moment.
·
Wednesday, 21 January 2015 00:06
·
0 Likes
·
0 Votes
·
0 Comments
·
Hello Mist,

I've managed to modify the code to have 3 variant for each attachment. As you can see in the post.php (attached) on line 994, I've set 3 different size and save these images. And in attachment.php file, there are 3 ways you can call the image (thumb, frontpage and cover) using this URL: index.php?option=com_easydiscuss&controller=attachment&task=displayFile&tmpl=component&size=cover&id=.
Please replace the attached files in:
../administrator/components/com_easydiscuss/tables/post.php
../components/com_easydiscuss/controllers/attachment.php

Hope this helps.
·
Wednesday, 21 January 2015 11:23
·
0 Likes
·
0 Votes
·
0 Comments
·
Thanks A LOT NICK. You saved me a lot of struggle.

Last question: Do you know any way to "re-process" the existing attachments with the new "setup" of post.php code ? I need to re-process all the existing attachments according to the new thing (creating all 3 sizes for existing attachments) and i don't know any way of doing it.

First solution that came into my mind is to manually edit them in Photoshop, i have 1000+ attachments, it can take some time, but at least i will do it only once .
From what i noticed, the attachments are not saved in a known image format, so i can't edit them with Photoshop.

So do you think for any solution regarding existing attachments ?

You helped me, a lot in multiple cases and for that i really thank you.
I wish there was a way of buying you a "beer" for this . Really, if there is, let me know.
·
Wednesday, 21 January 2015 21:39
·
0 Likes
·
0 Votes
·
0 Comments
·
Hello Mist,

You're welcome. And thanks for the offer. For this "re-process" thing, I think it is a bit tedious to do and I'm sorry, I can't help you with this.
·
Wednesday, 21 January 2015 23:09
·
0 Likes
·
0 Votes
·
0 Comments
·
View Full Post