[web2py] Re: What would be the best way to optimize/resize images after upload
It's using 'requires' because that will take the image and do something with it as a check, before validating the data and writing it to the database. In this case, it resizes the image as the "check". You might be able to find a validator that works with sqlform and replace it's check with the same function. On Monday, May 20, 2013 10:52:28 AM UTC-7, Derek wrote: > > That won't do anything. You want this: > db.table_name.picture.requires = RESIZE(200, 200) > > Form.requires probably does absolutely nothing. > > Your table name is 'test' and your field with the image is called 'pic' so > to adapt the imageutils.py example to your site would be this: > > db.test.pic.requires=RESIZE(200,200) > > > On Sunday, May 19, 2013 1:45:52 PM UTC-7, Dragan Matic wrote: >> >> Is there a way to make imageutils.py work with SQLFORM.FACTORY? It works >> perfectly with database tables but if I upload a picture through >> SQLFORM.factory like this: >> >> form = SQLFORM.factory(Field('pic', 'upload', uploadfolder=os.path.join( >> request.folder, 'uploads/')), Field('description', 'text'), table_name= >> 'test') >> >> form.table.pic.requires = RESIZE(50, 50) >> The picture is not resized. >> >> On Thursday, May 9, 2013 10:41:14 AM UTC+2, Niphlod wrote: >>> >>> there's also a /contrib/imageutils.py ready to use. >>> >>> Il giorno giovedì 9 maggio 2013 07:22:06 UTC+2, weheh ha scritto: There are numerous ways to resize uploaded images. Some are done via the web server. Others are done within the app. For a couple of my apps I use the python PIL package to resize uploaded images to thumbnails and the like. Here's a code fragment that shows how to do it: def resize_image(img_file, indx): from PIL import Image im = Image.open(img_file) im.thumbnail((w, h), Image.ANTIALIAS) return im You then have to use im.save('path', 'jpeg') to get a jpeg out. You also have to do a little extra work to save it to db or do some file management to discard the original, if you so desire. On Thursday, May 9, 2013 5:43:45 AM UTC+8, Dragan Matic wrote: > > Is there a way to automatically optimize and convert images after > users upload it on my web app? I am pretty sure lots of users will upload > uncompressed .bmp pictures or extra large pictures directly from camera. > I > think it would be best if I could resize and compress them immediately > after upload. What would be the best way to do it? > -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[web2py] Re: What would be the best way to optimize/resize images after upload
That won't do anything. You want this: db.table_name.picture.requires = RESIZE(200, 200) Form.requires probably does absolutely nothing. Your table name is 'test' and your field with the image is called 'pic' so to adapt the imageutils.py example to your site would be this: db.test.pic.requires=RESIZE(200,200) On Sunday, May 19, 2013 1:45:52 PM UTC-7, Dragan Matic wrote: > > Is there a way to make imageutils.py work with SQLFORM.FACTORY? It works > perfectly with database tables but if I upload a picture through > SQLFORM.factory like this: > > form = SQLFORM.factory(Field('pic', 'upload', uploadfolder=os.path.join( > request.folder, 'uploads/')), Field('description', 'text'), table_name= > 'test') > > form.table.pic.requires = RESIZE(50, 50) > The picture is not resized. > > On Thursday, May 9, 2013 10:41:14 AM UTC+2, Niphlod wrote: >> >> there's also a /contrib/imageutils.py ready to use. >> >> Il giorno giovedì 9 maggio 2013 07:22:06 UTC+2, weheh ha scritto: >>> >>> There are numerous ways to resize uploaded images. Some are done via the >>> web server. Others are done within the app. For a couple of my apps I use >>> the python PIL package to resize uploaded images to thumbnails and the >>> like. Here's a code fragment that shows how to do it: >>> >>> def resize_image(img_file, indx): >>> from PIL import Image >>> im = Image.open(img_file) >>> im.thumbnail((w, h), Image.ANTIALIAS) >>> return im >>> >>> You then have to use im.save('path', 'jpeg') to get a jpeg out. You also >>> have to do a little extra work to save it to db or do some file management >>> to discard the original, if you so desire. >>> >>> >>> >>> On Thursday, May 9, 2013 5:43:45 AM UTC+8, Dragan Matic wrote: Is there a way to automatically optimize and convert images after users upload it on my web app? I am pretty sure lots of users will upload uncompressed .bmp pictures or extra large pictures directly from camera. I think it would be best if I could resize and compress them immediately after upload. What would be the best way to do it? >>> -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[web2py] Re: What would be the best way to optimize/resize images after upload
Is there a way to make imageutils.py work with SQLFORM.FACTORY? It works perfectly with database tables but if I upload a picture through SQLFORM.factory like this: form = SQLFORM.factory(Field('pic', 'upload', uploadfolder=os.path.join( request.folder, 'uploads/')), Field('description', 'text'), table_name= 'test') form.table.pic.requires = RESIZE(50, 50) The picture is not resized. On Thursday, May 9, 2013 10:41:14 AM UTC+2, Niphlod wrote: > > there's also a /contrib/imageutils.py ready to use. > > Il giorno giovedì 9 maggio 2013 07:22:06 UTC+2, weheh ha scritto: >> >> There are numerous ways to resize uploaded images. Some are done via the >> web server. Others are done within the app. For a couple of my apps I use >> the python PIL package to resize uploaded images to thumbnails and the >> like. Here's a code fragment that shows how to do it: >> >> def resize_image(img_file, indx): >> from PIL import Image >> im = Image.open(img_file) >> im.thumbnail((w, h), Image.ANTIALIAS) >> return im >> >> You then have to use im.save('path', 'jpeg') to get a jpeg out. You also >> have to do a little extra work to save it to db or do some file management >> to discard the original, if you so desire. >> >> >> >> On Thursday, May 9, 2013 5:43:45 AM UTC+8, Dragan Matic wrote: >>> >>> Is there a way to automatically optimize and convert images after users >>> upload it on my web app? I am pretty sure lots of users will upload >>> uncompressed .bmp pictures or extra large pictures directly from camera. I >>> think it would be best if I could resize and compress them immediately >>> after upload. What would be the best way to do it? >>> >> -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[web2py] Re: What would be the best way to optimize/resize images after upload
there's also a /contrib/imageutils.py ready to use. Il giorno giovedì 9 maggio 2013 07:22:06 UTC+2, weheh ha scritto: > > There are numerous ways to resize uploaded images. Some are done via the > web server. Others are done within the app. For a couple of my apps I use > the python PIL package to resize uploaded images to thumbnails and the > like. Here's a code fragment that shows how to do it: > > def resize_image(img_file, indx): > from PIL import Image > im = Image.open(img_file) > im.thumbnail((w, h), Image.ANTIALIAS) > return im > > You then have to use im.save('path', 'jpeg') to get a jpeg out. You also > have to do a little extra work to save it to db or do some file management > to discard the original, if you so desire. > > > > On Thursday, May 9, 2013 5:43:45 AM UTC+8, Dragan Matic wrote: >> >> Is there a way to automatically optimize and convert images after users >> upload it on my web app? I am pretty sure lots of users will upload >> uncompressed .bmp pictures or extra large pictures directly from camera. I >> think it would be best if I could resize and compress them immediately >> after upload. What would be the best way to do it? >> > -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[web2py] Re: What would be the best way to optimize/resize images after upload
There are numerous ways to resize uploaded images. Some are done via the web server. Others are done within the app. For a couple of my apps I use the python PIL package to resize uploaded images to thumbnails and the like. Here's a code fragment that shows how to do it: def resize_image(table, indx): from PIL import Image On Thursday, May 9, 2013 5:43:45 AM UTC+8, Dragan Matic wrote: > > Is there a way to automatically optimize and convert images after users > upload it on my web app? I am pretty sure lots of users will upload > uncompressed .bmp pictures or extra large pictures directly from camera. I > think it would be best if I could resize and compress them immediately > after upload. What would be the best way to do it? > -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.