Header

  1. View current page

    suritam9님의 노트

Profile_img_60x60_01
1

devday4(1)

 제4회 Daum DevDay 프로젝트

 제목 : 다음 이미지 검색 후 영상처리 하여 블로그에 포스팅

  •  이미지 검색

    • xml 파서 - magpierss 와 snoopy(GPL)

      • thumbnail 링크를 remsave.php로 변수 img_url에 넘긴다.
      • remsave.php
      1. <?
        $save_dir = "C:/APM_Setup/htdocs/bin-release/Images"; // 저장 절대 경로
        $save_file = "searched.jpg"; // 저장 파일명
      2. if($img_url){// 리모트 주소가 있으면
        $open = fopen($img_url,"r");
        while(!feof($open)) $read .= fread($open,1024);
        fclose($open);
        }
      3. $save_file = sprintf("%s/%s",$save_dir, $save_file);

      4. if(file_exists($save_file)) // 저장할 경로에 이미 파일이 존재하면 지운다.
         unlink($save_file);
         
        $wopen = fopen($save_file,"w");// 저장한다.
        $write = fwrite($wopen,$read);
        fclose($wopen);
        ?>
        <html>
        <head>
        <meta http-equiv="refresh" content="0; url=ImageEditing.html"> <!-- 영상처리할 page로 이동한다. -->
        </head>
        </html>
      5. ?>
      •  ImageEditing.html 에서 로딩하는 Flex file - ImageEditing.mxml
      1. <?xml version="1.0" encoding="utf-8"?>
        <!--
         Jatin Desai (www.mojoflex.net)
         
         Please make a note that this code uses the ImageProcessing library
         posted at: http://blog.je2050.de/
         
         Track back url: http://www.mojoflex.net/2007/05/flex-image-processing.html
        -->
      2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()"
         layout="absolute">
         
         <mx:Script>
          <![CDATA[
           import com.ImageManipulation.*;
           import flash.display.*;
           import sjd.managers.*;
           //img 저장을 위한 부분 import 시작
                    import mx.graphics.ImageSnapshot;
                    import mx.graphics.codec.*;
           //img 저장을 위한 부분 import 끝
           //img 저장을 위한 변수 선언 시작
                    [Bindable] private var savedImageName:String;
                    private var saver:URLLoader;
           //img 저장을 위한 변수 선언 끝
                   
           private var imageFilter:ImageFilters;
           [Bindable]
           private var jpegData:ByteArray = null;
           [Bindable]
           private var imgName:String = "cs.jpg";
           
           private function init():void {
            var image:BitmapData = Bitmap( img.content ).bitmapData;
            var bmp:BitmapData = new BitmapData(img.width, img.height)
            
            // Grab pixels from original image
            bmp.copyPixels( image,
                new Rectangle( 0, 0, image.width , image.height ),
                new Point( 0, 0 ) );
            
            imageFilter = new ImageFilters(bmp);
            
            //ResizeManager.enableResize(imgcan, 50);
                        ImageSnapshot.defaultEncoder = PNGEncoder; //img 저장을 위한 init
           }
           
           private function DoBW():void {
            img.source = new Bitmap(imageFilter.MakeBW());
           }
           
           private function DoSepia():void {
            img.source = new Bitmap(imageFilter.MakeSepia());
           }
           
           private function DoEmboss():void {
            img.source = new Bitmap(imageFilter.EmbossImage());
           }
           
           private function DoTile():void {
            img.source = new Bitmap(imageFilter.MakeTile());
           }
           
           private function DoPixelate():void {
            img.source = new Bitmap(imageFilter.MakePixelate());
           }
           
           private function OutLineImage():void {
            img.source = new Bitmap(imageFilter.OutLineImage());
           }
           
           private function brightcontrast():void {
            if(bc.visible == false) {
             bc.visible=true;
             bc.includeInLayout=true;
            }
            img.source = new Bitmap(imageFilter.CorrectBrightNess(brightness.value, contrast.value));
           }
           
           private function InfraredControl():void {
            img.source = new Bitmap(imageFilter.InfraredImage());
           }
           
           private function RedEyeControl():void {
            img.source = new Bitmap(imageFilter.RedEyeImage());
           }
           
           private function TwirlControl():void {
            if(twrl.visible == false) {
             twrl.visible = true;
             twrl.includeInLayout = true;
            }
            img.source = new Bitmap(imageFilter.TwirlImage(centerX.value, centerY.value, angl.value*(Math.PI/4), radious.value));
           }
           /*
           private function saveImg():void {
            if(imgname.text.length > 0) {
             
             jpegData = imageFilter.saveImage();
             imgName = imgname.text;
             
             saveimg.saveImage.send();
            }
           }
           */
           private function imageLoaded(event:Event):void {
            img.removeEventListener(Event.COMPLETE, imageLoaded);
            init();
           }
           
           //img 저장을 위한 함수 시작
                    private function configureListeners( dispatcher:IEventDispatcher, handler:Function ):void
                    {
                        dispatcher.addEventListener(Event.CANCEL, handler);
                        dispatcher.addEventListener(Event.COMPLETE, handler);
                        dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, handler);
                        dispatcher.addEventListener(IOErrorEvent.IO_ERROR, handler);
                        dispatcher.addEventListener(Event.OPEN, handler);
                        dispatcher.addEventListener(ProgressEvent.PROGRESS, handler);
                        dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, handler);
                        dispatcher.addEventListener(Event.SELECT, handler);
                    }
                    private function releaseListeners( dispatcher:IEventDispatcher, handler:Function ):void
                    {
                        dispatcher.removeEventListener(Event.CANCEL, handler);
                        dispatcher.removeEventListener(Event.COMPLETE, handler);
                        dispatcher.removeEventListener(HTTPStatusEvent.HTTP_STATUS, handler);
                        dispatcher.removeEventListener(IOErrorEvent.IO_ERROR, handler);
                        dispatcher.removeEventListener(Event.OPEN, handler);
                        dispatcher.removeEventListener(ProgressEvent.PROGRESS, handler);
                        dispatcher.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, handler);
                        dispatcher.removeEventListener(Event.SELECT, handler);
                    }
                    private function saveImageHandler( event:Event ):void
                    {
                        switch( event.type )
                        {
                            case IOErrorEvent.IO_ERROR:
                            case SecurityErrorEvent.SECURITY_ERROR:
                                releaseListeners( saver, saveImageHandler);
                                mx.controls.Alert.show(event.toString());
                                break;
                            case Event.COMPLETE:
                                savedImageName = event.target.data as String;
                                releaseListeners( saver, saveImageHandler);
                                mx.controls.Alert.show('저장 완료');
                                break;
                        }               
                    }
                    private function captureImg():void {
                        var ohSnap:ImageSnapshot = ImageSnapshot.captureImage(img);
                        var base64decodeValue:String = ImageSnapshot.encodeImageAsBase64(ohSnap);
                        if(!saver)
                        {
                            saver = new URLLoader;
                            configureListeners( saver, saveImageHandler);
                        }
      3.                 var fnrand:Date = new Date(); // 시간을 받는다.
                        var request:URLRequest = new URLRequest("saver.php");
                        request.method = "post";
                        var param:URLVariables = new URLVariables;
                        param.data = base64decodeValue;
                        param.extension = "jpg";
      4.                 param.datetime = fnrand.getTime();// 시간도 보낸다.
                        request.data = param;
                        saver.load( request );
      5.                 navigateToURL( new URLRequest( "../devday.php?datetime=" + param.datetime ), "_self" );
                    }
                    //img 저장을 위한 함수 선언 끝
          ]]>
         </mx:Script>
         
         <mx:Panel width="100%" height="100%" title="Image Editing" paddingTop="5" paddingBottom="5"
          horizontalAlign="center" verticalAlign="middle" cornerRadius="10"
          borderColor="#000000" color="#ffffff" fontSize="12" headerHeight="50" backgroundAlpha="0.6" backgroundColor="#000000">
          <mx:Canvas id="imgcan">
           <mx:Image id="img" source="Images/searched.jpg" /> //저장된 이미지의 로딩
          </mx:Canvas>
          
          <mx:ControlBar id="cb" width="100%" height="60" color="#000000" horizontalAlign="center" enabled="false" >
           <!--
           <mx:Button id="save" label="Save Image" click="saveBox.visible=true; saveBox.includeInLayout=true;" visible="false" />
           -->
           <mx:Button id="apply" label="Apply Changes" click="captureImg()" />
           <mx:Button id="bw" label="B/W" click="DoBW()" />
           <mx:Button id="sepia" label="Sepia" click="DoSepia()" />
           <mx:Button id="Infrared" label="Infrared" click="InfraredControl()" />
           <mx:Button id="bright" label="Bright / Contrast" click="brightcontrast()" />
           <mx:Button id="colorAd" label="Outline" click="OutLineImage()" />
           <mx:Button id="redeye" label="Red Eye" click="RedEyeControl()" />
           <mx:Button id="emboss" label="Emboss" click="DoEmboss()" />
           <mx:Button id="Tile" label="Tile" click="DoTile()" />
           <mx:Button id="pixelate" label="Pixelate" click="DoPixelate()" />
           <mx:Button id="twirl" label="Twirl" click="TwirlControl()" />
          </mx:ControlBar>
          
         </mx:Panel>
           <mx:VBox x="10" y="70" width="100%" height="70">
              <mx:Form  width="100%">
                  <mx:FormItem label="">
                      <mx:TextInput text="{savedImageName}" width="300"/>
                  </mx:FormItem>
              </mx:Form>
            </mx:VBox>
         <mx:VBox id="bc" horizontalAlign="right" verticalAlign="bottom" visible="false" includeInLayout="false"
          height="100%" width="100%" bottom="70" right="10">
           
          <mx:TitleWindow title="Brightness Contrast" showCloseButton="true" close="bc.visible=false; bc.includeInLayout=false;"
           width="200" height="150">
           
           <mx:Label text="Brightness" />
           <mx:HSlider id="brightness" value="40" minimum="0" maximum="100" snapInterval="1" change="brightcontrast()" />
           
           <mx:Label text="Contrast" />
           <mx:HSlider id="contrast" value="1.2" minimum="0" maximum="2" snapInterval="0.1" change="brightcontrast()" />
           
          </mx:TitleWindow>
          
         </mx:VBox>
         
         <mx:VBox id="twrl" horizontalAlign="right" verticalAlign="bottom" visible="false" includeInLayout="false"
          height="100%" width="100%" bottom="240" right="10">
           
          <mx:TitleWindow title="Twirl" showCloseButton="true" close="twrl.visible=false; twrl.includeInLayout=false;"
           width="200" height="250">
           
           <mx:Label text="X" />
           <mx:HSlider id="centerX" value="0" minimum="0" maximum="{img.width}" snapInterval="1" change="TwirlControl()" />
           
           <mx:Label text="Y" />
           <mx:HSlider id="centerY" value="0" minimum="0" maximum="{img.height}" snapInterval="1" change="TwirlControl()" />
           
           <mx:Label text="Angle" />
           <mx:HSlider id="angl" value="0" minimum="0" maximum="180" snapInterval="1" change="TwirlControl()" />
           
           <mx:Label text="Radious" />
           <mx:HSlider id="radious" value="0" minimum="0" maximum="500" snapInterval="1" change="TwirlControl()" />
           
          </mx:TitleWindow>
          
         </mx:VBox>
      6. </mx:Application>

History

Last edited on 06/28/2008 03:44 by suritam9

Comments (0)

You must log in to leave a comment. Please sign in.