Professional Web Applications Themes

Image conversion ... - Ruby

Hi, is there any Ruby code snippets I can use to transform my photo to lower resolution, uniform size but maintaining aspect ration, etc ...? Thanks...

  1. #1

    Default Image conversion ...

    Hi, is there any Ruby code snippets I can use to transform my photo to lower
    resolution, uniform size but maintaining aspect ration, etc ...?

    Thanks


    Useko Guest

  2. #2

    Default Re: Image conversion ...

    On Tue, 3 Feb 2004 08:47:16 -0500, "Useko Netsumi"
    <net> wrote:
     

    RMagick (http://raa.ruby-lang.org/list.rhtml?name=rmagick) has this
    functionality, but it's way more than a code snippet.
    Tim Guest

  3. #3

    Default Re: Image conversion ...

    > Hi, is there any Ruby code snippets I can use to transform my photo to lower 

    The doentation of RMagick has a lot of examples.

    http://rmagick.rubyforge.org/



    Carlos Guest

  4. #4

    Default Re: Image conversion ...

    On Tue, 3 Feb 2004, Tim Hunter wrote:
     
    >
    > RMagick (http://raa.ruby-lang.org/list.rhtml?name=rmagick) has this
    > functionality, but it's way more than a code snippet.[/ref]

    if you have image magick installed you can also simply

    mogrify -size 50x50 image.jpg

    do

    man mogrify

    -a

    --

    ATTN: please update your address books with address below!

    ================================================== =============================
    | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
    | PHONE :: 303.497.6469
    | ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
    | STP :: http://www.ngdc.noaa.gov/stp/
    | NGDC :: http://www.ngdc.noaa.gov/
    | NESDIS :: http://www.nesdis.noaa.gov/
    | NOAA :: http://www.noaa.gov/
    | US DOC :: http://www.commerce.gov/
    |
    | The difference between art and science is that science is what we
    | understand well enough to explain to a computer.
    | Art is everything else.
    | -- Donald Knuth, "Discover"
    |
    | /bin/sh -c 'for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done'
    ================================================== =============================

    Ara.T.Howard Guest

  5. #5

    Default Re: Image conversion ...

    Useko Netsumi wrote: 
    I use GD and this lil' code, it keeps aspect ratio and ONLY works on jpg
    and png, since you say you use php, this could look familiar, the code
    could be *better* but does what I want use it or take it as reference,
    usage of copyResampled would give better output but haven't been able to
    use it.

    *warning nuby code ahead*

    require "GD"
    class Thumber
    #imgpath=Full path to src image i.e.
    "/home/osuka/pics/good_looking_me.jpg"
    #thumb_dir=dir path ro dest directory i.e. "/home/osuka/backups/"
    *notice* trailing /
    #newx=new image width i.e. 320
    #newy=new image height i.e. 240
    #prefix=prefix to add to given image i.e. "thumb_"
    #type=image type of uotput thumb i.e. "jpg"|png|gif <-depends
    on GD image write support this particular code
    #uses only jpg and png, haven't need anything else, or in gif case
    can modified it to use an external app like Magick.
    #or gif2png
    def initialize(imgpath,thumb_dir,newx,newy,prefix,type )
    prefix=prefix
    imgpath=imgpath
    thumb_dir=thumb_dir
    type=type

    if(imgpath.downcase=~/[a-zA-Z0-9]+.(jpg||jpeg)+/)
    #comment out if noisy
    puts srctype="jpeg"
    srcimg=GD::Image.new_from_jpeg(imgpath)
    ratio=srcimg.width.to_f/srcimg.height
    elsif(imgpath.downcase=~/[a-zA-Z0-9]+.(png)+/)
    #comment out if noisy
    puts srctype="png"
    srcimg=GD::Image.new_from_png(imgpath)
    ratio=srcimg.width.to_f/srcimg.height
    elsif(imgpath.downcase=~/[a-zA-Z0-9]+.(gif)+/)
    #comment out if noisy
    puts srctype="gif"
    srcimg=GD::Image.new_from_gif(imgpath)
    ratio=srcimg.width.to_f/srcimg.height
    else
    #comment out if noisy
    puts "other"
    end
    newx=newx
    newy=newy
    #comment out if noisy
    puts ratio
    if(newy>newx)
    newy=(newx/ratio).round
    else
    puts newx=(newy*ratio).round
    end

    if(File.exists?(thumb_dir+prefix+File.basename( imgpath)))
    #comment out if noisy
    puts "file exist"
    else
    #comment out if noisy
    puts "file doesn't exist"
    dstimg=GD::Image.new(newx,newy)

    srcimg.copyResized(dstimg,0,0,0,0,newx,newy,s rcimg.width,srcimg.height)
    thumbf=File.new(thumb_dir+prefix+File.basename( imgpath),"wb")
    if(type=="jpg")
    dstimg.jpeg(thumbf,85)
    elsif(type=="png")
    dstimg.png(thumbf)
    else(type=="gif")
    #dstimg.gif(thumbf,85)
    end
    end

    end
    end

    #example usage:
    #img1="e:/adartse/DNA.JPG"
    #mypic=Thumber.new(img1,"e:/temp/",80,100,"","jpg")




    Osuka Guest

  6. #6

    Default Re: Image conversion ...

    Hi Osuka, I will try what you suggested.

    Thank you very much for your help.

    "Osuka Adartse" <net.mx> wrote in message
    news:net.mx... [/ref]
    lower 
    > I use GD and this lil' code, it keeps aspect ratio and ONLY works on jpg
    > and png, since you say you use php, this could look familiar, the code
    > could be *better* but does what I want use it or take it as reference,
    > usage of copyResampled would give better output but haven't been able to
    > use it.
    >
    > *warning nuby code ahead*
    >
    > require "GD"
    > class Thumber
    > #imgpath=Full path to src image i.e.
    > "/home/osuka/pics/good_looking_me.jpg"
    > #thumb_dir=dir path ro dest directory i.e. "/home/osuka/backups/"
    > *notice* trailing /
    > #newx=new image width i.e. 320
    > #newy=new image height i.e. 240
    > #prefix=prefix to add to given image i.e. "thumb_"
    > #type=image type of uotput thumb i.e. "jpg"|png|gif <-depends
    > on GD image write support this particular code
    > #uses only jpg and png, haven't need anything else, or in gif case
    > can modified it to use an external app like Magick.
    > #or gif2png
    > def initialize(imgpath,thumb_dir,newx,newy,prefix,type )
    > prefix=prefix
    > imgpath=imgpath
    > thumb_dir=thumb_dir
    > type=type
    >
    > if(imgpath.downcase=~/[a-zA-Z0-9]+.(jpg||jpeg)+/)
    > #comment out if noisy
    > puts srctype="jpeg"
    > srcimg=GD::Image.new_from_jpeg(imgpath)
    > ratio=srcimg.width.to_f/srcimg.height
    > elsif(imgpath.downcase=~/[a-zA-Z0-9]+.(png)+/)
    > #comment out if noisy
    > puts srctype="png"
    > srcimg=GD::Image.new_from_png(imgpath)
    > ratio=srcimg.width.to_f/srcimg.height
    > elsif(imgpath.downcase=~/[a-zA-Z0-9]+.(gif)+/)
    > #comment out if noisy
    > puts srctype="gif"
    > srcimg=GD::Image.new_from_gif(imgpath)
    > ratio=srcimg.width.to_f/srcimg.height
    > else
    > #comment out if noisy
    > puts "other"
    > end
    > newx=newx
    > newy=newy
    > #comment out if noisy
    > puts ratio
    > if(newy>newx)
    > newy=(newx/ratio).round
    > else
    > puts newx=(newy*ratio).round
    > end
    >
    > if(File.exists?(thumb_dir+prefix+File.basename( imgpath)))
    > #comment out if noisy
    > puts "file exist"
    > else
    > #comment out if noisy
    > puts "file doesn't exist"
    > dstimg=GD::Image.new(newx,newy)
    >
    >[/ref]
    srcimg.copyResized(dstimg,0,0,0,0,newx,newy,s rcimg.width,srcimg.height



    Ruby Guest

  7. #7

    Default Re: Image conversion ...

    Thanks Ara, I'll get Rmagick and try them out.

    "Ara.T.Howard" <ngdc.noaa.gov> wrote in message
    news:ngdc.noaa.gov... [/ref][/ref]
    lower 
    > >
    > > RMagick (http://raa.ruby-lang.org/list.rhtml?name=rmagick) has this
    > > functionality, but it's way more than a code snippet.[/ref]
    >
    > if you have image magick installed you can also simply
    >
    > mogrify -size 50x50 image.jpg
    >
    > do
    >
    > man mogrify
    >
    > -a
    >
    > --
    >
    > ATTN: please update your address books with address below!
    >
    >[/ref]
    ================================================== ==========================
    === 
    \"\x3a\x2d\x29\x0a\"";done' 
    ================================================== ==========================
    === 


    Useko Guest

  8. #8

    Default Re: Image conversion ...

    On Tue, 03 Feb 2004 18:57:21 -0500, Useko Netsumi wrote:
     [/ref]

    Using RMagick, the Ruby equivalent to this command is:

    require 'RMagick'
    include Magick

    img = Image.read("image.jpg").first
    img.change_geometry("50x50") { |cols, rows|
    img.resize!(cols, rows)
    }
    img.write("image.jpg")
    Tim Guest

  9. #9

    Default Re: Image conversion ...

    I would start with this:
    http://rmagick.rubyforge.org/

    Having used JMagick to build an HtmlGallery generation app, I may
    rewrite in ruby to build a gtk gui into it.

    Shameless plug:

    http://www.goof.com/~mmead/HtmlGallery/



    -matt

    On Mon, Feb 09, 2004 at 06:28:23AM +0900, Useko Netsumi wrote: 

    --
    matthew c. mead

    http://www.goof.com/~mmead/


    matthew Guest

  10. #10

    Default Re: Image conversion ...

    Do they have the mswin32 version of RMagick? They mention to have the cygwin
    version but how do I mix and match between mswin32 ruby and cygwin RMagick?

    I do have a development Linux server in the same machine with my Windows
    Development. I have to use the windows for my day jobs and use it
    exclusively. Perhaps if there are the mswin32 version of all Ruby related
    apps would be convenience for beginer such as myself.

    Thanks

    "matthew c. mead" <com> wrote in message
    news:com... [/ref]
    lower 
    >
    > --
    > matthew c. mead
    >
    > http://www.goof.com/~mmead/
    >
    >[/ref]


    Useko Guest

  11. #11

    Default Re: Image conversion ...

    "Useko Netsumi" <net> wrote: 

    Besides other solutions you could use the command line tool or the
    library behind xnview
    http://perso.wanadoo.fr/pierre.g/xnview/enhome.html. It's easy to
    install and easy to use via Ruby scripts.

    Simple things can be done by fox but I wouldn't recommend it for batch
    image processing.

    Cheers
    Sascha
    Sascha Guest

Similar Threads

  1. Question conversion of image size
    By thameem in forum Brainstorming Area
    Replies: 0
    Last Post: November 14th, 01:59 PM
  2. Guru: Image conversion
    By Useko in forum PHP Development
    Replies: 7
    Last Post: February 4th, 09:43 PM
  3. SVG->PNG image conversion
    By Ian.H in forum PHP Development
    Replies: 6
    Last Post: December 27th, 01:31 PM
  4. Replies: 22
    Last Post: July 29th, 04:34 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139