Chandan Pitta wrote:
> Code reuse is always good. But once again the question arises, how
> does freevo handle changes to WWW_IMAGE_THUMBNAIL_SIZE if images are
> already cached. I am guessing we may need another function in
> fileops.py like
freevo cache --rebuild should do it. It may not work until I've done the
code to delete files from the cache.
>
> def is_image_cached(scaled_image_path):
> new_size = config.WWW_IMAGE_THUMBNAIL_SIZE
> new_size = self.get_fit_to_rectangle_size(size, new_size)
> create_scaled_image = False
> if os.path.exists(scaled_image_path):
> # if the scaled image already exists then make sure it is
> scaled to the correct size
> new_image = imlib2.open(scaled_image_path)
> if new_image.width != new_size[0] or new_image.height != new_size[1]:
> os.remove(scaled_image_path)
> create_scaled_image = True
> else:
> create_scaled_image = True
> return !create_scaled_image
>
> You will also want to add the timestamp check in the above function.
> And this is what we need to do both with freevo cache and webserver
>
> thumb_filename = util.cache_www_thumbnail_path(filename)
> if not util.is_image_cached(thumb_filename):
> util.cache_www_image(filename)
>
> But if I were to do it, I would actually drag the checking for
> accuracy of the thumbnail into cache_www_image(filename). That way
> cache_www_thumbnail_path() is called only once and the main program
> will only have to do
Doesn't matter it's upto kaa.imlib2 to do this, less work for the webserver.
> util.cache_www_image(filename)
>
> And the function will cache if there is no cached image or original
> image has changed or WWW_IMAGE_THUMBNAIL_SIZE has changed. It will do
> nothing otherwise. The caller will never have to know. Or we can add a
> return which tells the caller if a cached image is created or not. Let
> me know what you think
Lets not try to change the design of cache, it would lead to too many
changes. Cache only works on time stamps and the version of the cache
generators.
I don't expect people to change WWW_IMAGE_THUMBNAIL_SIZE much if at all.
so a cache rebuild is fine.
Duncan
>
> On 1/2/07, Duncan Webb <[EMAIL PROTECTED]> wrote:
>> Chandan Pitta wrote:
>>> Try this patch.
>> Patch worked fine now in svn rel-1 at r8917
>>
>> I have these functions in util.fileops.py which is now updated from the
>> patch you have sent. They is called when "freevo cache" is run.
>>
>> def cache_www_thumbnail_path(filename):
>> '''returns the path to the thumbnail image for a given filename
>> '''
>> file_ext_index = filename.rindex(".")
>> file_ext = filename[file_ext_index:].lower()
>> if file_ext == ".gif":
>> file_ext += ".jpg"
>> imagepath = filename[:file_ext_index].replace("/", "_") + file_ext
>> thumb_path = os.path.join(www_image_cachedir(), imagepath)
>> return thumb_path
>>
>> def cache_www_image(filename):
>> '''creates a webserver thumbnail image and returns its size.
>> '''
>> thumb_path = www_cache_thumbnail_path(filename)
>> image = imlib2.open(filename)
>> thumb = image.scale_preserve_aspect(config.WWW_IMAGE_THUMBNAIL_SIZE)
>> thumb.save(thumb_path)
>> return thumb.size
>>
>> What this means is that we're not quite finished yet :( sorry. Cache
>> needs to cache every image, size doesn't matter it's determined by the
>> timestamp between the original item and the cached item.
>>
>> The functions is called like this:
>> sinfo = os.stat(filename)
>> thumb = util.cache_www_thumbnail_path(filename)
>> try:
>> if os.stat(thumb)[stat.ST_MTIME] > sinfo[stat.ST_MTIME]:
>> files.remove(filename)
>> except OSError:
>> pass
>>
>
> I am assuming this is a code you came up with and did not actually
> commit to svn? Seems like you are checking to see if the thumbnail
> timestamp > original image TS then you delete the original file? The
> condition should be reversed and the thumnail image has to be deleted
> not the original right?
>
> Frankly I do not mind doing the code over as long as it is cleaner and
> more maintainable.
>
> Regards
> Chandan
>
>
>> All this means it that it makes this code simpler, you don't need to
>> worry about threshold sizes or aspect ratios, the helper functions in
>> util.fileops does this for you.
>>
>> So the library.rpy only needs to check if the
>> cache_www_thumbnail_path(path) exist and if not call
>> cache_www_image(thumb_path).
>>
>> This will be much cleaner and easier to maintain. When you get some time
>> could you do the changes.
>>
>> Many thanks
>> Duncan
>>
>>
>>> On 1/2/07, Duncan Webb <[EMAIL PROTECTED]> wrote:
>>>> Chandan Pitta wrote:
>>>>> Sorry attached the wrong diff file. See this one
>>>> I can't apply this patch, says that it has been previously detected.
>>>>
>>>> Will you try an svn update, I applied Wout's patch at 8912 and your
>>>> one-liner after.
>>>>
>>>> Thanks
>>>> Duncan
>>
>>
>> -------------------------------------------------------------------------
>> Take Surveys. Earn Cash. Influence the Future of IT
>> Join SourceForge.net's Techsay panel and you'll get the chance to share your
>> opinions on IT & business topics through brief surveys - and earn cash
>> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
>> _______________________________________________
>> Freevo-devel mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/freevo-devel
>>
>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys - and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Freevo-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/freevo-devel
>
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Freevo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-devel