Re: Help with implementation of file uploads and thumbnail generation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 06/06/2014 04:41 AM, Hammad Haleem wrote:
Hello All,

I was developing a Web API for Uploading and managing content. For the
Feodra College Project. The API would allow basic stuff like Uploading
Deleting and Uploading revisions of Content. Content can be either of
following types namely Documents( PDF / DOC etc ), Images, Videos and
Audio recordings.

The problem I am facing here is with generating thumbnail images for
these content types. Mainly for the Video and Document types.  Can
someone guide me on how this can be done? Or any previous efforts by
anyone.

Hi,
I used this snipped in my python project were I needed the same thing:

from PIL import Image
from PIL.ExifTags import TAGS

def resize_image(path, name):
    size = 200, 200

    infile = os.path.join(path, name)
    outfile = os.path.join(path, "thumb_" + name)
    print outfile
    if infile != outfile:
        try:
            im = Image.open(infile)
            im.thumbnail(size, Image.ANTIALIAS)
            im.save(outfile, "JPEG")
        except IOError, ex:
print "cannot create thumbnail for '{0}': {1}".format(infile, ex)


def handle_uploaded_file(f):
with open(os.path.join(settings.MEDIA_ROOT, f.name), 'wb+') as destination:
        for chunk in f.chunks():
            destination.write(chunk)
        destination.close()
        resize_image(settings.MEDIA_ROOT, f.name)

It uses the python PIL module, which you should check out, it's pretty easy to use. No sure if it works for the video.

--Jirka


--
Regards
Hammad Haleem



_______________________________________________
infrastructure mailing list
infrastructure@xxxxxxxxxxxxxxxxxxxxxxx
https://admin.fedoraproject.org/mailman/listinfo/infrastructure


_______________________________________________
infrastructure mailing list
infrastructure@xxxxxxxxxxxxxxxxxxxxxxx
https://admin.fedoraproject.org/mailman/listinfo/infrastructure





[Index of Archives]     [Fedora Development]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [KDE Users]

  Powered by Linux