A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: Can PHP get pixel hex values of a jpg?

  1. #1
    Senior Member
    Join Date
    Nov 2000
    Posts
    166

    Can PHP get pixel hex values of a jpg?

    Does anyone know if PHP can get color values for pixels in an image? For example if I wanted to get the hex value for the pixel that is 50 pixels across and 50 pixels down.

  2. #2
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    there is a getpixel function in the GD library

    Musicman

  3. #3
    Senior Member
    Join Date
    Nov 2000
    Posts
    166
    I don't know much about the GD library. Is that usually installed standard with most PHP installations? How can i check if it is installed?

  4. #4
    __OSX powered__ nucleuz's Avatar
    Join Date
    Aug 2000
    Location
    Norway
    Posts
    836
    do a phpinfo(); file and you'll see.
    NuCleuZ :: PHPVolcano :: Blog

  5. #5
    Junior Member
    Join Date
    Apr 2004
    Posts
    13

    can php do the same with swfs?

    do you know if php can do the same getPixel function with a swf? Or, for that matter do you know of any other method to extract a pixel colour in a swf?

  6. #6
    proud new daddy! LuxFX's Avatar
    Join Date
    May 2000
    Location
    Dunsinane
    Posts
    1,148
    There is a SWF module for PHP called MING. I don't know much about it, but I doubt it has the capability you're looking for. A swf needs to be run with the flash plugin to get the final outcome -- a script looking for a pixel value wouldn't know what frame to look on, what actionscript might be running that would change the color of the pixel, or what movies have been loaded on top of that movie that would have their own pixel color.

    And, for that matter, I doubt swf are stored with pixels in mind, either. SWFs are vector graphics at heart, so anything stored in them would be stored with numerical coordinate values instead of pixel coordinates.

    Sorry!
    For War's a banker, flesh his gold. There by the furnace of Troy's field, Where thrust meets thrust, he sits to hold His scale, and watch the spear-point sway; And back to waiting homes he sends Slag from the ore, a little dust To drain hot tears from hearts of friends

    - Aeschylus, Agamemnon

  7. #7
    Senior Member
    Join Date
    Nov 2003
    Location
    Las Vegas
    Posts
    770
    Here's a widget I thought might be helpful. It is a swf movie that loads a jpeg via loadmovie, then you click on the point you want to find the color for and it scales it to a very large size. Then a color picker with RGB sliders and a hex# display appears for you to attempt to match the color. The color picker can be moved around for ease of color matching particular pixels.

    http://jerryscript.hostrocket.com/fl...ormatcher.html

    You must have the swf movie and the jpeg on the same computer, it doesn't have file upload support, but it could easily be added. This is probably buggy, I just threw it together after reading this thread.

    No FLA, I used Ming, but here's the AS (FMX6):
    Code:
    createTextField('loaderInfo',1,450,180,0,0);
    with(loaderInfo){
    type='static';
    autosize='center';
    selectable=multiline=border=background=false;
    text='Enter the relative path to the image';
    }
    createTextField('loaderInput',2,200,210,500,20);
    with(loaderInput){
    type='input';
    border=background=true;
    bordercolor='0x000000';
    backgroundColor='0xffffff';
    text='greetingcard.jpg';
    }
    createEmptyMovieClip('loaderButton',3);
    with(loaderButton){
    _x=450;
    _y=250;
    createTextField('loaderSubmit',4,0,0,0,0);
    with(loaderSubmit){
    type='static';
    autosize='center';
    selectable=false;
    border=background=true;
    backgroundColor='0x000000';
    text='Load File';
    textFormat=getTextFormat();
    textFormat.color='0xffffff';
    setTextFormat(textFormat);
    }
    }
    loaderButton.onRollOver=function(){
    this.loaderSubmit.backgroundColor='0xffffff';
    textFormat=this.loaderSubmit.getTextFormat();
    textFormat.color='0x000000';
    this.loaderSubmit.setTextFormat(textFormat);
    };
    loaderButton.onRollOut=function(){
    this.loaderSubmit.backgroundColor='0x000000';
    textFormat=this.loaderSubmit.getTextFormat();
    textFormat.color='0xffffff';
    this.loaderSubmit.setTextFormat(textFormat);
    };
    loaderButton.onPress=function(){
    this.loaderSubmit.backgroundColor='0xc6c6c6';
    textFormat=this.loaderSubmit.getTextFormat();
    textFormat.color='0x000000';
    this.loaderSubmit.setTextFormat(textFormat);
    };
    loaderButton.onRelease=function(){
    this.loaderSubmit.backgroundColor='0x000000';
    textFormat=this.loaderSubmit.getTextFormat();
    textFormat.color='0xffffff';
    this.loaderSubmit.setTextFormat(textFormat);
    _root.imageURL=loaderInput.text;
    createEmptyMovieClip('imageHolder',1);
    imageHolder.loadMovie(_root.imageURL);
    removeMovieClip('loaderInput');
    removeMovieClip('loaderButton');
    _root.onEnterFrame=function(){
    if(imageHolder._width>0 || imageHolder._height>0){
    //imageHolder._x=(Stage.width-imageHolder._width)/2;
    //imageHolder._y=(Stage.height-imageHolder._height)/2;
    delete this.onEnterFrame;
    imageHolder.choosePixel();
    }
    };
    };
    
    MovieClip.prototype.choosePixel=function(){
    this.createEmptyMovieClip('crossHairs',10);
    this.crossHairs._x=imageHolder._width/2;
    this.crossHairs._y=imageHolder._height/2;
    with(this.crossHairs){
    lineStyle(2);
    moveTo(-30,0);
    lineTo(30,0);
    moveTo(0,-30);
    lineTo(0,30);
    }
    this.onPress=function(){
    this.crossHairs.startDrag(1);
    };
    this.onRelease=this.onReleaseOutside=function(){
    stopDrag();
    this._x=450-this.crossHairs._x*100;
    this._y=225-this.crossHairs._y*100;
    this._xscale=this._yscale=10000;
    removeMovieClip(this.crossHairs);
    
    // create rgb color picker
    _root.createEmptyMovieClip('cp',9500);
    with(_root.cp){
    _x=450;_y=225;
    createEmptyMovieClip('bg',11);
    with(bg){
    lineStyle(1,0x000000);beginFill(0x000000);
    lineTo(255/2+5,0);lineTo(255/2+5,14);lineTo(0,14);lineTo(0,0);
    endFill();
    }}
    
    _root.cp.onMouseDown=function(){
    if(hitTest(_root._xmouse,_root._ymouse,true) && _root.cp.r.hitTest(_root._xmouse,_root._ymouse,false)==false && _root.cp.g.hitTest(_root._xmouse,_root._ymouse,false)==false && _root.cp.b.hitTest(_root._xmouse,_root._ymouse,false)==false){
    with(_root.cp){
    startDrag(0,0,0,Stage.width,Stage.height);
    }
    }
    };
    
    _root.cp.onMouseUp=function(){
    stopDrag();
    };
    
    _root.cp.onMouseMove=function(){
    if(_root.cp.hitTest(_root._xmouse,_root._ymouse,false)){
    }else{
    stopDrag();
    }
    if(dragging){
    rv=this.r._x*2+1;
    gv=this.g._x*2+1;
    bv=this.b._x*2+1;
    rv=rv.toString(16).length<2?'0'+rv.toString(16):rv.toString(16);
    gv=gv.toString(16).length<2?'0'+gv.toString(16):gv.toString(16);
    bv=bv.toString(16).length<2?'0'+bv.toString(16):bv.toString(16);
    _root.nc.setRGB('0x'+rv+gv+bv);
    _root.cp.display.text='0x'+rv+gv+bv;
    }
    updateAfterEvent();
    };
    
    _root.cp._xscale=200;
    _root.cp._yscale=200;
    
    for(c=1;c<4;c++){
    if(c==1){cv='r';cf='0xff0000';
    }else{if(c==2){cv='g';cf='0x00ff00';
    }else{cv='b';cf='0x0000ff';}}
    _root.cp.createEmptyMovieClip(cv,c+9500);
    with(eval('_root.cp.'+cv)){
    lineStyle(0.25,0xffffff);
    beginFill(cf);moveTo(0,-2);lineTo(5,-2);lineTo(5,2);lineTo(0,2);lineTo(0,-2);endFill();
    _x=0;_y=c-3+c*4;
    _root.cp[cv].onMouseDown=function(){
    if(hitTest(_root._xmouse,_root._ymouse,false)){
    drawing=false;
    _root.dragging=true;
    startDrag(0,0,_y,255/2,_y);
    }
    };
    _root.cp[cv].onMouseUp=function(){
    _root.dragging=false;
    stopDrag();
    };
    }
    }
    _root.nc=new Color(_root.cp.bg);
    _root.cp.createTextField('display',9510,225/4,20,0,0);
    with(_root.cp.display){
    type='dynamic';
    border=background=true;
    autosize='center';
    }
    // end rgb color picker
    delete this.onRelease;
    delete this.onReleaseOutside;
    delete this.onPress;
    };
    };

  8. #8
    Junior Member
    Join Date
    Apr 2004
    Posts
    13
    I'm glad you've posted Jerry! What you've built on your site

    http://jerryscript.hostrocket.com/fl...wing2JPEG.html

    is the closest I have got to what I need. The project I am working on has an interface that enables users to drag on library items; bitmaps, vector art, text whatever. They can create as many instances as they wish and are able to texture any item, which has been done with masks and a background bitmap. Also there are drawing tools, the same as whats shown on your site. However the fundamental difference, and hence why I now believe it is impossible, is the Ming module is redrawing those lines into a jpg and not converting straight pixel for pixel. In the case of this project, whats required is an automated process that is capable of determining pixel colours of a swf of its own and exporting that data to an image file. I find it a little frustrating that Flash doesnt provide any feature capable of this, little own some feature that can return a colour at a point.

    What you've made is really amazing! And if you ever come across a way to determine pixel colours I would love to hear it!

  9. #9
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    as an alternative to Jerry's method I( have implemented a script that creates a self-contained swf.
    Both methods require some preparation - one is creating another movie (which is sort of copying the design movie and thewn removing and changing a few things) where the other requires creating a library of jpeg or png images of any objects that you can manipulate

    What you are looking for is a basic flash player - and although you do not need animation for it, you cannot really do away with actionscripts

    Musicman

  10. #10
    Senior Member
    Join Date
    Nov 2003
    Location
    Las Vegas
    Posts
    770
    Ming is only used to create the SWF movies, both in the examples I've posted, and any SWF output from those examples. When converting to JPG/PNG, the GD library is used.

    In both cases, the pixel values are not passed, only the shape/color data. Flash does not use a pixel based format (bitmaps), it uses a vector based format, and therefor cannot determine the indiviual pixel color values without a considerable amount of calculation to determine shape/fill positions.

    I believe there may be third party software that can do a screenshot of a flash movie, and this could be passed to a PHP/GD script to determine a single pixel's value, but it would be a heavy load on any backend setup.

    You could use a Flash front-end GUI with a PHP/GD backend to create the user's product, and then determine pixel values based upon GD, without the extreme load on the server mentioned above.

    Good luck on your project!

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center