Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

resizing JPG images

 [1/15] from: jmalv::hotmail::com at: 20-Oct-2001 13:52


Does anybody have any sample code that show how to resize a JPG image to a fixed pixel size Thanks Jose

 [2/15] from: cybarite:sympatico:ca at: 20-Oct-2001 9:03


10/20/01 7:52:23 AM, "Jose Manuel Alvarez" <[jmalv--hotmail--com]> wrote:
>Does anybody have any sample code that show how to resize a JPG image to a >fixed pixel size
Maybe this is what you want: view layout [image (bay-peg: load %bay.jpg) 500x800] This loads it once so that it can be used again view layout [image bay-peg 100x100] And the image can be loaded from the internet via bay-peg: load http://www.rebol.com/view/bay.jpg view layout [image bay-peg 500x423] and the better version might be to use the REBOL caching capability bay-peg: load-thru/binary http://www.rebol.com/view/bay.jpg (Strangely the load and load-thru are different in that load-thru needs the binary refinement otherwise you get a less-than-satisfactory result.) Then after you have retrieved it and stored in your public cache, which you will be asked to agree to per the sandbox model, REBOL will use the cached version... so you can access it without being connected to the internet

 [3/15] from: jmalv:hotma:il at: 22-Oct-2001 12:38


What about resizing in a Core script without having to use View. If View is the answer, how can I save the resized picture (sorry, but I am View newbie !) The application I have in mind is a photo album where you publish thumbnails of all your jpg pictures Thanks

 [4/15] from: carl:cybercraft at: 23-Oct-2001 0:55


On 22-Oct-01, Jose Manuel Alvarez wrote:
> What about resizing in a Core script without having to use View.
I don't think core can process images.
> If > View is the answer, how can I save the resized picture (sorry, but I > am View newbie !)
View can load JPGs (and GIFs and PNGs) but the only compressed image format it can save in is PNG. For instant, cut and paste the following five lines into the console... bay: load-thru/binary http://www.rebol.com/view/bay.jpg thumb-size: bay/size / 2 thumb-bay: to-image layout [origin 0x0 image bay thumb-size] save/png %thumb-bay.png thumb-bay view layout [image bay image thumb-bay] and they should save a quarter-sized version of the bay image to disk and then display both versions in a window. Don't be afraid of using PNGs for your thumbnails. As they're a loss-less image format they probably make better thumnails than JPGs.
> The application I have in mind is a photo album where you publish > thumbnails of all your jpg pictures
<<quoted lines omitted: 21>>
>> needs the binary refinement otherwise you get a >> less-than-satisfactory result.)
-- Carl Read

 [5/15] from: jmalv:ho:tmail at: 22-Oct-2001 15:02


The problem with this solution is the size of the thumbnail which is 17K while the initial image is 8K (and a jpg thumbnail would be 3K)

 [6/15] from: jasonic:nomadics at: 22-Oct-2001 9:59


bay: load-thru/binary http://www.rebol.com/view/bay.jpg thumb-size: bay/size / 2 thumb-bay: to-image layout [origin 0x0 image bay thumb-size] save/png %thumb-bay.png thumb-bay view layout [image bay image thumb-bay] thanks for the example..
> The problem with this solution is the size of the thumbnail which is 17K > while the initial image is 8K (and a jpg thumbnail would be 3K)
hmm.. Yes this is problem for me too. And it looks like it can only be solved at the moment using installation-demanding external image processing tools [GIMP,ImageMagick, PIL=PythonImagingLibrary, or the excellent commercial MM Fireworks4 ] bay.png = 59kb a good looking JPEG version of same [80%] is only 9kb.. Image compresssion is an art and a science, but lack of any JPEG save control in REBOL/View really concerns me. Typical example: digital video still capture 640x480 BMP averages 240kb. A decent JPEG version of same: 40kb What to do? Are there problems/plans for REBOL/View to support JPEG? Recent loss of DSL service here [Rhythms bankruptcy] has made me painfully aware again of download sizes, and of REBOL's highly aeronautic design! - Jason

 [7/15] from: greggirwin:mindspring at: 22-Oct-2001 10:09


Hi Jose, << What about resizing in a Core script without having to use View. If View is the answer, how can I save the resized picture (sorry, but I am View newbie!) >> You'd have to do the scaling yourself. I.e. you can load the data from the file in Core but I don't know of any way to make it do the scaling for you. --Gregg

 [8/15] from: holger:rebol at: 22-Oct-2001 9:26


On Mon, Oct 22, 2001 at 09:59:06AM -0400, Jason Cunliffe wrote:
> What to do? > Are there problems/plans for REBOL/View to support JPEG?
For saving ? No, not at this time.
> Recent loss of DSL service here [Rhythms bankruptcy] has made me painfully > aware again of download sizes, and of REBOL's highly aeronautic design!
Yes, which is why we did not add a JPEG saver. It would significantly increase the size of the binary. Saving an image as JPEG is rather complicated. It involves color space conversion, DCT, quantizing etc. It might be a good feature for Command though. For Command and Command/View the size of the binary is not as important as for View, because it is not distributed as widely. Same reason why Command has SSL and other binaries don't. There are some ways to reduce the size of saved PNGs even from within REBOL. You could, e.g., quantize the image to less than 24 bits per pixel before saving. -- Holger Kruse [holger--rebol--com]

 [9/15] from: jasonic:nomadics at: 22-Oct-2001 13:33


> > What to do? > > Are there problems/plans for REBOL/View to support JPEG? > > For saving ? No, not at this time. > > > Recent loss of DSL service here [Rhythms bankruptcy] has made me
painfully
> > aware again of download sizes, and of REBOL's highly aeronautic design! > Yes, which is why we did not add a JPEG saver. It would significantly
<<quoted lines omitted: 4>>
> because it is not distributed as widely. Same reason why Command has > SSL and other binaries don't.
Holger, Thanks for your prompt answer. I am curious how many Kb JEPG saver would add? And how others feel about this or some options for it? Adding built-in JPEG /save to REBOL/Command makes a lot of sense: - As server side commercial version, features are surely more way important than disk space / download time. - Server side raelly needs strong JPEG control - Extra incentive for Rebol customers to buy /Command, stronger eparaton of RT products etc Of course it is not _that_ big a deal on web servers to use soem otehr toolkits to do teh JPEG stuff. But not having the feature does lessen the pragmatic scope of REBOL as a distributed technology. Easy image upload/transfer/sharing/conversion is central to so many applications. Just as adding Rebol dialects and functions to handle vector graphics technology: SVG and SWF. One example of scripted vector toolkit is Ming [PHP/Python/Ruby] http://opaque.net/ming/ Trying to do deistributed graphics with REBOl is so tantaliznig. The design philisophy and communcaitions infrasture is there, but the file doformat and highlevel graphics object handling is sorely missing. Weither REBOl has to roll its own, or make it really smooth for people to include other graphic libraries and formats. This would be be positive change I think and help speed REBOL's growth.
> There are some ways to reduce the size of saved PNGs even from within > REBOL. You could, e.g., quantize the image to less than 24 bits per > pixel before saving.
Thanks. I 'll do some tests on these. - Jason

 [10/15] from: carl:cybercraft at: 23-Oct-2001 9:09


On 23-Oct-01, Jose Manuel Alvarez wrote:
> The problem with this solution is the size of the thumbnail which is > 17K while the initial image is 8K (and a jpg thumbnail would be 3K)
Sigh - I hadn't checked the file size...
>> From: Carl Read <[carl--cybercraft--co--nz]> >> Reply-To: [rebol-list--rebol--com]
<<quoted lines omitted: 21>>
>> loss-less image format they probably make better thumnails than >> JPGs.
-- Carl Read

 [11/15] from: ammonjohnson:y:ahoo at: 22-Oct-2001 22:24


I also would strongly recomend you ask the users what they would like to see, maybe offer a *plugin* for download that will allow for JPG saves. Thanks!! Ammon

 [12/15] from: media:quazart at: 23-Oct-2001 8:57


YESS!!! a plugin for jpeg saving is VERY usefull ! even if its slow (like a rebol script doing the binary handywork) ... usually I need jpeg as part of my image building script within the web site/intranet builder. I don't care if it takes a few seconds for the script to generate all of the images, but I really would like the images to end up as jpegs... currently I must go into to photoshop as an intermediate step... or save to png... which I cannot integrate easily with other tools than browsers. If you really must make it a purchase incentive, maybe just a little support site with a jpeg .dll and some rebol functions which integrate the dll within rebol... so we all have some standard way of saving jpeg... this way, those who really need it , will spend the time to install the plugin . -Max

 [13/15] from: d4marcus:dtek:chalmers:se at: 25-Oct-2001 20:26


For saving jpegs, I suppose you need View/Pro to do it all from Rebol. You would save/bmp the image, then call cjpeg or some similar tool. On Mon, 22 Oct 2001, Jose Manuel Alvarez wrote:
> The application I have in mind is a photo album where you publish thumbnails > of all your jpg pictures
It's probably not what you want, but this simple photoalbum app generates thumbnails as you call it. It's unacceptable on a slow computer though. REBOL [ Title: "Thumbnail creator / photoalbum" Date: 24-Oct-2001 Author: "Marcus Petersson" File: %thumbnail.r ] to-thumbnail: func [ img [image! file!] tsize [pair! integer!] "Size or height" /local sx sy y ] [ y: integer? tsize tsize: to-pair tsize img: load img either image? img [ sx: img/size/x / to-decimal tsize/x sy: img/size/y / to-decimal tsize/y sx: img/size / either y [sy] [max sx sy] layout [img: image img sx] ] [ layout [img: image tsize black] ] to-image img ] photoalbum: func ["View pictures using thumbnails" images [block!] "Block of filenames" tsize [pair! integer!] "Thumbnail size" /local l thumbs im width ] [ width: 0 thumbs: copy [origin 1x1 space 2x2 backcolor white across] l: length? images repeat i l [ append thumbs compose/deep [ image (im: to-thumbnail images/:i tsize) (to-string last split-path pick images i) [ im: pick images (i) if error? try [rv im] [print ["Cannot display" im]]] ] width: width + im/size/x if width > (system/view/screen-face/size/x / 2) [ width: 0 append thumbs 'return] ] view/new layout thumbs do-events ] rv: func [f [file! word! image!] b [block! unset!] /local t] [ any [value? 'b b: copy []] insert b [origin 0x0 pad 1x1 image #"q" [unview] f] either image? f [t: ""] [t: f f: load f] view/new/title layout b reform [t mold to-paren f/size] ] help photoalbum photoalbum request-file 80 halt Marcus ------------------------------------ If you find that life spits on you calm down and pretend it's raining

 [14/15] from: jmalv:hotmai:l at: 26-Oct-2001 10:09


This is really useful as a local photoalbum ! The solution I'm thinking of is a script that interfaces to Imagemagick.org C++ library. It would be great to be able to select from photoalbum.r the images to publish and then create a photoalbum website with both the JPG thumbnails and the normal images. Pls let me know if you´re working on a Imagemagick interface. This might be a quicker/easier solution than resizing JPGs with a Rebol script Thanks

 [15/15] from: d4marcus:dtek:chalmers:se at: 27-Oct-2001 0:31


On Fri, 26 Oct 2001, Jose Manuel Alvarez wrote:
> Pls let me know if you´re working on a Imagemagick interface. This might be > a quicker/easier solution than resizing JPGs with a Rebol script
Uhm, no. :-) Marcus ------------------------------------ If you find that life spits on you calm down and pretend it's raining

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted