Class | PiceditController |
In: |
app/controllers/picedit_controller.rb
|
Parent: | ApplicationController |
WorkFile | = | 'temp.jpg' |
# File app/controllers/picedit_controller.rb, line 199 199: def backspace 200: 201: session[:state]=0 202: session[:selected_item]=0 203: session[:title]='select an image effect' 204: session[:pic]=session[:motherpic] 205: session[:freeze]=nil 206: redirect_to :action => "index" 207: end
# File app/controllers/picedit_controller.rb, line 137 137: def blur(path,blurfile,percentblur) 138: path= path.chomp 139: blurfile= blurfile.chomp 140: percentblur= percentblur.to_i/5.0 141: picwidth= 560 ; #width of the pic (in pixels) 142: picheight= 400; #height of the pic (pixels) 143: 144: 145: if File.exists?(blurfile) 146: # logger.info("filepresent:#{blurfile}exists") 147: else 148: img= Magick::Image.read(path).first #reads the image specfied by the user path 149: img= img.scale(560,400) #scales image to 640x480 150: img=img.blur_image(0.0,percentblur) 151: img.write(blurfile) 152: end 153: end
# File app/controllers/picedit_controller.rb, line 42 42: def border(path,borderfile,borderval) 43: path= path.chomp 44: borderfile= borderfile.chomp 45: borderval= (borderval.to_i/10)*5 46: picwidth= 560 ; 47: picheight= 400; 48: if File.exists?(borderfile) 49: # logger.info("filepresent:#{borderfile}exists") 50: else 51: img= Magick::Image.read(path).first #reads the image specfied by the user path 52: img= img.scale(560,400) #scales image to 640x480 53: img.border(borderval,borderval,'rgb(255,110,140)').write(borderfile) 54: end 55: end
# File app/controllers/picedit_controller.rb, line 174 174: def charcoal(path,coalfile,coalpercent) 175: path= path.chomp 176: coalfile= coalfile.chomp 177: coalpercent= coalpercent.to_i/10.0 178: picwidth= 560 ; #width of the pic (in pixels) 179: picheight= 400; #height of the pic (pixels) 180: if File.exists?(coalfile) 181: logger.info("filepresent:#{coalfile}exists") 182: else 183: img= Magick::Image.read(path).first #reads the image specfied by the user path 184: img= img.scale(560,400) #scales image to 640x480 185: img=img.charcoal(radius=0.0, sigma=coalpercent) 186: 187: img.write(coalfile) 188: end 189: 190: end
# File app/controllers/picedit_controller.rb, line 11 11: def designers 12: 'Designer:<a href="http://anmolanand.wordpress.com/">Anmol 13: Anand</a>' 14: end
# File app/controllers/picedit_controller.rb, line 328 328: def extras 329: # logger.info("reached extras") 330: if session[:state]==1 331: @selected_item = session[:freeze]%get_choices.size 332: end 333: if session[:pic].match("(/images/.*)$") 334: @picfile=$1 335: else 336: @picfile=session[:pic] 337: end 338: # logger.info("mypic: #{@picfile}") 339: end
# File app/controllers/picedit_controller.rb, line 24 24: def first_time 25: 26: session[:motherpic]=session[:pic]=get_selected_pic 27: session[:selected_item]=0 28: session[:freeze]=nil 29: # session[:separator]=',' 30: session[:percentage]=session[:stepsize].to_i 31: #state 0 => we are choosing what to change 32: #state 1 => we have chosen what to change 33: session[:state]=0 34: session[:title]='select an image effect' 35: 36: #session[:expiry]= 37: #'<meta http-equiv="Expires" content="0" />' 38: #so that any older copy of temp.jpg in the cache is not used 39: redirect_to :action => "index" 40: end
# File app/controllers/picedit_controller.rb, line 102 102: def flip(path,flipfile) 103: path= path.chomp 104: flipfile= flipfile.chomp 105: 106: picwidth= 560 ; #width of the pic (in pixels) 107: picheight= 400; #height of the pic (pixels) 108: 109: if File.exists?(flipfile) 110: # logger.info("filepresent:#{flipfile}exists") 111: else 112: img= Magick::Image.read(path).first #reads the image specfied by the user path 113: img= img.scale(560,400) #scales image to 640x480 114: img=img.flip 115: img.write(flipfile) 116: end 117: end
# File app/controllers/picedit_controller.rb, line 120 120: def flop(path,flopfile) 121: path= path.chomp 122: flopfile= flopfile.chomp 123: 124: picwidth= 560 ; #width of the pic (in pixels) 125: picheight= 400; #height of the pic (pixels) 126: 127: if File.exists?(flopfile) 128: #logger.info("filepresent:#{flopfile}exists") 129: else 130: img= Magick::Image.read(path).first #reads the image specfied by the user path 131: img= img.scale(560,400) #scales image to 640x480 132: img=img.flop 133: img.write(flopfile) 134: end 135: end
# File app/controllers/picedit_controller.rb, line 15 15: def get_choices 16: session[:choices]=['border','wave','rotate','blur','radialblur','charcoal'] 17: end
# File app/controllers/picedit_controller.rb, line 195 195: def get_freeze 196: session[:freeze] ||= session[:selected_item] 197: end
# File app/controllers/picedit_controller.rb, line 18 18: def get_percentage 19: session[:percentage]=((get_selected_item )* ("#{get_stepsize}".to_i)) % 100 20: 21: session[:percentage] 22: end
# File app/controllers/picedit_controller.rb, line 8 8: def get_selected_pic 9: session[:picfile] ||= "yes.jpeg" 10: end
# File app/controllers/picedit_controller.rb, line 209 209: def process_choice selected_choice 210: 211: if session[:state]==1 212: session[:state]=0 213: session[:selected_item]=0 214: session[:freeze]=nil 215: session[:title]='select an image effect' 216: session[:motherpic]=session[:pic] 217: else 218: session[:state]=1 219: 220: session[:title]="#{session[:percentage]}%"+ 221: get_choices[get_freeze%session[:choices].size] 222: logger.info("freeze:#{session[:freeze]}") 223: 224: end 225: logger.info("sel_state:#{session[:state]}") 226: logger.info("croppercent:#{session[:percentage]}") 227: 228: end
# File app/controllers/picedit_controller.rb, line 155 155: def radialblur(path,bfile,blurpercent) 156: path= path.chomp 157: bfile= bfile.chomp 158: blurpercent=(blurpercent*2.0) 159: if File.exists?(bfile) 160: #logger.info("filepresent:#{bfile}exists") 161: else 162: img= Magick::Image.read(path).first #reads the image specfied by the user path 163: img= img.scale(560,400) #scales image to 640x480 164: img=img.radial_blur(blurpercent) 165: img.write(bfile) 166: end 167: end
# File app/controllers/picedit_controller.rb, line 80 80: def rotate(path,rotatefile,rotateangle) 81: path= path.chomp 82: rotatefile= rotatefile.chomp 83: 84: picwidth= 560 ; #width of the pic (in pixels) 85: picheight= 400; #height of the pic (pixels) 86: if File.exists?(rotatefile) 87: # logger.info("filepresent:#{rotatefile}exists") 88: else 89: img= Magick::Image.read(path).first #reads the image specfied by the user path 90: img= img.scale(560,400) #scales image to 640x480 91: img=img.rotate!(rotateangle) 92: img.write(rotatefile) 93: end 94: end
# File app/controllers/picedit_controller.rb, line 192 192: def selected(str) 193: session[:motherpic]= session[:pic] 194: end
# File app/controllers/picedit_controller.rb, line 231 231: def updownevent 232: logger.info("reached updownevent") 233: if session[:state]==1 234: 235: 236: #session[:percentage]=(get_selected_item % 9+1) * 10 237: session[:percentage]=get_percentage 238: 239: tempchoice = get_choices 240: choice=tempchoice[get_freeze % tempchoice.size] 241: logger.info("choice:#{choice}") 242: 243: st=(Dir.pwd).chomp("/public")+"/public/images/" 244: session[:mainfile]=if session[:motherpic]=~/home/ 245: session[:motherpic] 246: else 247: st+session[:motherpic] 248: end 249: 250: 251: case choice 252: 253: when "border" 254: filename="#{session[:mainfile]}".gsub(/\./,"b#{session[:percentage]}"+".") 255: 256: 257: session[:pic]=filename 258: 259: session[:title]="#{session[:percentage]} pixel "+get_choices[get_freeze%session[:choices].size] 260: 261: border(session[:mainfile],filename,session[:percentage]) 262: 263: when "wave" 264: filename="#{session[:mainfile]}".gsub(/\./,"w#{session[:percentage]}"+".") 265: 266: 267: session[:pic]=filename 268: 269: session[:title]="#{session[:percentage]}%"+get_choices[get_freeze%session[:choices].size] 270: 271: wave(session[:mainfile],filename,session[:percentage]) 272: 273: when "rotate" 274: filename="#{session[:mainfile]}".gsub(/\./,"rot#{session[:percentage]}"+".") 275: 276: 277: session[:pic]=filename 278: 279: session[:title]=get_choices[get_freeze%session[:choices].size]+" #{session[:percentage]} degrees" 280: 281: rotate(session[:mainfile],filename,session[:percentage]) 282: 283: 284: when "blur" 285: filename="#{session[:mainfile]}".gsub(/\./,"bl#{session[:percentage]}"+".") 286: 287: 288: session[:pic]=filename 289: 290: session[:title]="#{session[:percentage]}%"+get_choices[get_freeze%session[:choices].size] 291: 292: blur(session[:mainfile],filename,session[:percentage]) 293: 294: 295: when "radialblur" 296: filename="#{session[:mainfile]}".gsub(/\./,"rdb#{session[:percentage]}"+".") 297: 298: 299: session[:pic]=filename 300: 301: session[:title]="#{session[:percentage]}%"+get_choices[get_freeze%session[:choices].size] 302: 303: radialblur(session[:mainfile],filename,session[:percentage]) 304: 305: 306: 307: 308: 309: when "charcoal" 310: filename="#{session[:mainfile]}".gsub(/\./,"co#{session[:percentage]}"+".") 311: 312: 313: session[:pic]=filename 314: 315: session[:title]="#{session[:percentage]}%"+get_choices[get_freeze%session[:choices].size]+"effect" 316: 317: charcoal(session[:mainfile],filename,session[:percentage]) 318: 319: 320: 321: 322: 323: 324: 325: end 326: end 327: end
# File app/controllers/picedit_controller.rb, line 59 59: def wave(path,wavefile,percentwave) 60: path= path.chomp 61: wavefile= wavefile.chomp 62: percentlength=percentwave*4 63: percentwave= percentwave.to_i/2.0 64: 65: picwidth= 560 ; #width of the pic (in pixels) 66: picheight= 400; #height of the pic (pixels) 67: if File.exists?(wavefile) 68: # logger.info("filepresent:#{wavefile}exists") 69: else 70: img= Magick::Image.read(path).first #reads the image specfied by the user path 71: img= img.scale(560,400) #scales image to 640x480 72: 73: img=img.wave(percentwave, percentlength) 74: 75: img.write(wavefile) 76: end 77: end