Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Images from - Android

by clanrbr (Novice)
on Dec 18, 2012 at 12:12 UTC ( [id://1009349]=perlquestion: print w/replies, xml ) Need Help??

clanrbr has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks. Android applications is sending images to perl script IN JAVA
ByteArrayOutputStream byteArrayBitmapStream = new ByteArrayOutputStrea +m(); bitmapPicture.compress(Bitmap.CompressFormat.JPEG, COMPRESSION_QUALITY +, byteArrayBitmapStream); byte[] b = byteArrayBitmapStream.toByteArray();
and they are putting this in a string and send it to the script. Here is the perl part i get this binary file.
if ( open ( PICTF,"> smepath/file.jpeg" ) ) { binmode PICTF; print PICTF $contentpic; close (PICTF); } my ($x, $y, $info) = imgsize("somepath/file.jpeg");
The $info yell there is no such known file format. So i checked the binary code that app sends me. I saw it is JFIF and this is JPEG. Any suggestions what i might do to fix this ? I want to save it to JPEG. When i dump the binary code to .txt and change it to .jpeg image is not shown. What should i do i am using IMAGER module. P.S. Not the image is the problem i tried with LWP and it made it binary and i've saved it. The problem comes from JAVA.

Replies are listed 'Best First'.
Re: Images from - Android
by BrowserUk (Patriarch) on Dec 18, 2012 at 12:33 UTC
    when i dump the binary code to .txt and change it to .jpeg image is not shown.

    JFIF is the correct internal identifier for .jpg's; changing it to .JPG doesn't make any sense at all.

    If your image tools aren't recognising the file format, it probably means that it is getting corrupted in some (other) way.

    I suspect, based upon your (very limited) code snippet, that you are probably forgetting to binmode the socket you are reading from, and/or using readline (or <$fh>) to read from that socket, without having changed the input separator.

    To get a proper answer, you'd need to show the full code -- or at the very least, the code where you open the socket and read from it -- but the full code would save you and us time.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    RIP Neil Armstrong

      This app is posting the image to perl script.
      my $req = new CGI; $contentpic=$req->param("pic") if ($req->param("pic") ); if ( open ( PICTF,">somepath/image.jpeg" ) ) { binmode PICTF; print PICTF $contentpic; close (PICTF); my ($x, $y, $info) = imgsize("somepath/image.jpeg"); $info=lc($info); $info=~s/jpg/jpeg/; if ( $info eq "jpeg" ) { my $logo=Imager->new(); $logo->read(file =>"somepath/mylogo.png", type => 'png'); my $imgorg=Imager->new(); $imgorg->read(file => "somepath/image.jpeg", type => $info); my $img=$imgorg->scale(xpixels=>280); my ($tx,$ty)=((280-$logosize[0]-$logooffs),(int(280*$y/$x)-$log +osize[1]-$logooffs)); $img->rubthrough( src=>$logo, tx=>$tx,ty=>$ty ); $img->write(file => "somepath/image.jpeg", type => $info); $result=1; }
        This app is posting the image to perl script.

        You're missing the point. Where and how do you obtain the data held in $contentpic?


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

        RIP Neil Armstrong

Re: Images from - Android
by zentara (Archbishop) on Dec 18, 2012 at 12:31 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1009349]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-03-29 15:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found