creating mini avatars
cosmicelf
Joined: 2005-08-21
Posts: 153 |
![]() |
I would like for to be able to have a cache of a minature version of all the highligted photos in my user albums. Currently I use these photos for the user profiles and as an avatar for their posts on the forum. I have a place in other parts of my CMS however where I would like a 60px version of these. Any suggestions? |
|
cosmicelf
Joined: 2005-08-21
Posts: 153 |
![]() |
Is there a way I can use the G2 API in order to create these mini avatars and save them to a directory of my choice? Is there a way I could intercept changes made to the highlighted image in the UserAlbums and trigger a process to update the mini avatars? |
|
valiant
Joined: 2003-01-04
Posts: 32509 |
![]() |
maybe look at the mediawiki integration or the wp integration. i guess at least the mediawiki integration creates some resizes. not sure though. |
|
cosmicelf
Joined: 2005-08-21
Posts: 153 |
![]() |
Is there an explanation somewhere on how to create "derivative images" ? |
|
valiant
Joined: 2003-01-04
Posts: 32509 |
![]() |
as usual, there are examples. see modules/core/ItemEditAlbum.inc search for resize -> |
|
cosmicelf
Joined: 2005-08-21
Posts: 153 |
![]() |
In order to do this properly I can see that I am going to have to trigger the mini_avatar generation when the thumbnail is generated. This probably means every time a user changes the highlight image for their gallery or changes the thumbnail itself with a crop. Is it currently possible for me to create a module which would create a mini_thumbnail when either of these things happens? |
|
valiant
Joined: 2003-01-04
Posts: 32509 |
![]() |
sure. but IMO you should create your mini-avatar when the user visits the profile in your CMS. |
|
cosmicelf
Joined: 2005-08-21
Posts: 153 |
![]() |
the 48px mini avatars will be used all over the site. I could potentially make a "recreate avatar" link within the profile page perhaps. Is there any documentation I can find anywhere about how to make a gallery2 module like this? IE. How do I get in there to tell gallery when to execute my code? The mini_avatar only need be created whenever the "highlited image" thumbnail changes. |
|
valiant
Joined: 2003-01-04
Posts: 32509 |
![]() |
your module needs to liste for Entity::save events: http://gallery.menalto.com/node/36885#comment-134279 you can learn from other modules... |
|
cosmicelf
Joined: 2005-08-21
Posts: 153 |
![]() |
for the time being i will be creating the avatars myself with php function. list ($ret,$thumbnails) = GalleryCoreApi::fetchThumbnailsByItemIds($Ids); How do I get the file path? $handle = imagecreatefromjpeg($url); Warning: imagecreatefromjpeg(): 'http://dev.tribalharmonix.org/phpgallery/main.php?g2_view=core.DownloadItem&g2_itemId=2582' is not a valid JPEG file in |
|
valiant
Joined: 2003-01-04
Posts: 32509 |
![]() |
GalleryCoreApi::fetchThumbnailsByItemIds($Ids); will not generate thumbnails for you. it will only return thumbnails that already exist. but most items should already have a thumbnail... list($id,$thumbnail)=each($thumbnails); $thumbnails as returned by fetchThumbnailsByItemIds is an array($id => $thumbnail, $id => $thumbnail, ...) for each $id in array $ids. so the above code doesn't make sense. $avatarID = $thumbnail->getId(); is fine, if $thumbnail was a thumbnail object. but because of your previous line, this is probably wrong. once you have the thumbnail id, to generate url, use: and doesn't make any sense at all. or...i guess you want to generate create a mini thumbnail based on the thumbnail of g2. |
|
cosmicelf
Joined: 2005-08-21
Posts: 153 |
![]() |
Quote:
GalleryCoreApi::fetchThumbnailsByItemIds($Ids); i realize that. that line is to fetch the thumbnail objects. Quote:
$avatarID = $thumbnail->getId(); actually $thumbnail is a thumbnail object.. i do get the $avatarID without a problem. the thing is I don't wan to generate the URL. If I can open the image then i can resize it and save it where I want. |
|
cosmicelf
Joined: 2005-08-21
Posts: 153 |
![]() |
soo... rather than.. $url = $urlGen->generateUrl(array('view' => 'core.DownloadItem', 'itemId' => $thumbnailId)); how do i get the path to the actual physical file on the hard drive? i'm really trying to get this done as soon as i can now.. also.. what was that better way to do this? |
|
cosmicelf
Joined: 2005-08-21
Posts: 153 |
![]() |
I still can't figure out why this doesn't work... $handle=imagecreatefromjpeg("http://dev.tribalharmonix.org/phpgallery/main.php?g2_view=core.DownloadItem&g2_itemId=2582"); I have a feeling the "better way" has something to do with this. Quote:
- Derivatives: Given a $GalleryItemID or even a thumbnail object.. How do I create a 48px square image and save it in $DOCUMENT_ROOT/image_db/minivatars/ ? |
|
cosmicelf
Joined: 2005-08-21
Posts: 153 |
![]() |
duplicate. oops |
|
valiant
Joined: 2003-01-04
Posts: 32509 |
![]() |
if you use G2's api to create resizes (the 48px mini avatar would be a resize and not a thumbnail) then it would be stored in G2's storage directory. you'd have to use the $url = $urlGenerator->generateUrl(array('view' => 'core.DownloadItem', 'itemId' => $miniAvatarId)); how to create a mini avatar resize? 1. get the $item object for the photo |
|
cosmicelf
Joined: 2005-08-21
Posts: 153 |
![]() |
if it will store them in the gallery database and put them in the G2 storage directory then this is not what i want to do. how do i get the path to the actual physical thumbnail file on the hard drive? This does not work even though it supposesedly points to a valid jpeg. Quote:
$handle=imagecreatefromjpeg("http://dev.tribalharmonix.org/phpgallery/main.php?g2_view=core.DownloadItem&g2_itemId=2582"); |
|
cosmicelf
Joined: 2005-08-21
Posts: 153 |
![]() |
The reason I definately want to modify the thumbnail as opposed to creating a new resize is because the user then has the option to choose the crop for the thumbnail. I know I've asked this a number of times already but... i still really want to know. how do i get the path to the actual physical thumbnail file on the hard drive? The url does not seem to do it. unless you can tell me why the above imagecreatefromjpeg would not work. thanks. |
|
valiant
Joined: 2003-01-04
Posts: 32509 |
![]() |
get the thumbnail object see modules/core/classes/GalleryDerivative.class |
|
cosmicelf
Joined: 2005-08-21
Posts: 153 |
![]() |
Is there anything weird about the jpg's generated by G2 for thumbnails besides the extension? Have any ideas why I would get this error? Warning: imagecreatefromjpeg(): '/website/gallerydata/cache/derivative/2/5/2582.dat' is not a valid JPEG file in the file exists. |
|
cosmicelf
Joined: 2005-08-21
Posts: 153 |
![]() |
ah.. i see.. because that particular one is a png does gallery make thumbnails png's if the main file is a png? if so, is there a way to make it a consistent file type? |
|
valiant
Joined: 2003-01-04
Posts: 32509 |
![]() |
g2 makes thumbnail png's and jpg's i guess that's it. maybe also gif. you shouldn't care about it. and no, there's no way to force to generate .jpg for png originals. use $derivative->getMimeType() to get the mimetype of the derivative. |
|
cosmicelf
Joined: 2005-08-21
Posts: 153 |
![]() |
i wrote my own function that i am creating the thumbnails with and putting them my /image_db/mini_avatars/ dir rather than in the g2 system. but my function makes all the mini_thumbnails jpegs. |
|
valiant
Joined: 2003-01-04
Posts: 32509 |
![]() |
after all, you could do: |
|
cosmicelf
Joined: 2005-08-21
Posts: 153 |
![]() |
oh but wait.. will a resize contain the user's modified crop preference? |
|
valiant
Joined: 2003-01-04
Posts: 32509 |
![]() |
please study ItemEditPhoto.inc function handleRequest(). |
|
cosmicelf
Joined: 2005-08-21
Posts: 153 |
![]() |
sorry, I don't see what I am supposed to be looking for. Can i make resizes of my 111px user cropped thumbnail or do I have to go from the original? does this take into account the user's thumbnail crop preferences? GalleryCoreApi::newFactoryInstanceByHint |
|
valiant
Joined: 2003-01-04
Posts: 32509 |
![]() |
you'll use the original. |
|
cosmicelf
Joined: 2005-08-21
Posts: 153 |
![]() |
i don't really understand. say i have a 640 x 480 jpeg. i want a 48px x 48px version of the thumbnail (not the original). If I use the original to make a resize (as opposed to the thumbnail) that is 48px x 48px how does it know where i told it to crop the thumbnail? is that what this does? GalleryCoreApi::fetchPreferredSource($item) |
|
valiant
Joined: 2003-01-04
Posts: 32509 |
![]() |
then stop talking about thumbnails. as i explained before, you'll have to copy code from modules/core/ItemEditPhoto.inc function handleRequest. then you can run list ($ret, $derivative, $wasBuilt) = to generate the binary image file. |
|