convert image (.jpg) to .raw (in php) [8b/c, no alpha] help pls!

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
elliot.
Posts: 7
Joined: 2017-12-18T08:52:29-07:00
Authentication code: 1152

convert image (.jpg) to .raw (in php) [8b/c, no alpha] help pls!

Post by elliot. »

hi there,

i need a little bit help achieving the topic and i hope you guys will help me :).
my task is to fetch an user avatar (.jpg) from a directory in php, convert it to a .raw file and output the result (php echo). the resulting .raw will be downloaded by an external application and will be rendered onto the screen with a game engine. before i started writing my php script i manually tested to convert the avatar ("convert avatar.jpg a.raw") and render it so i can be sure this step works. sadly it doesnt work and i think the problem is the alpha channel, cuz the image gets totally f*cked up by the engine renderer if an alpha channel is in the pic.

In photoshop i do this:
-crop the image ofc
-use 8bit per channel
-select areas for alpha channel and creating a new channel (alpha) out of it (if there is none i dont createn an alpha channel nor do i select areas)
-save the file with alpha channel unchecked and transparency checked
Image
Image

so how can i achieve this with imagemagick? preferably without saving it to hdd directly in a php file?
im glad about any input =)

thank you!!
Last edited by elliot. on 2017-12-18T12:52:11-07:00, edited 1 time in total.
elliot.
Posts: 7
Joined: 2017-12-18T08:52:29-07:00
Authentication code: 1152

Re: convert image (.jpg) to .raw (in php)

Post by elliot. »

i tried "convert avatar.jpg -alpha off avatar.raw"
with the same result... :(
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert image (.jpg) to .raw (in php)

Post by fmw42 »

I do not understand what you want? JPG does not support transparency. So turning alpha off does nothing. Do you want a raw file with no transparency or one with opaque alpha channel?

Code: Select all

convert image.jpg image.rgb
should work. Note the suffix is . rgb not .raw

What is your IM version and platform, since syntax may vary.
elliot.
Posts: 7
Joined: 2017-12-18T08:52:29-07:00
Authentication code: 1152

Re: convert image (.jpg) to .raw (in php)

Post by elliot. »

hi fmw42, thank you for your reply!

input file can be png or jpg.
as output i need a raw file without transparency or alpha channel (8bit per channel).
i dont really know what other attributes the file needs to be drawn correctly, thats why i posted my photoshop export settings which generate working images.
heres an example of a engine loadable image:
http://singularity.wtf/styles/snglrty/m ... avatar.raw (29x29px).

Version: ImageMagick 6.7.7-10 2017-07-31 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP
running system is ubuntu 14.04.

here is the error it produces:
Image
green is the 29x29 avatar i linked u above.
red is another, bigger avatar converted with imagemagick.

best regards
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert image (.jpg) to .raw (in php)

Post by fmw42 »

Why are you checking transparency in your PS window if you want a file without transparency?

If you want file without transparency and depth 8 (24 bits total) for 3 channels, then

Code: Select all

convert image.png -alpha off -depth 8 image.rgb
ImageMagick needs the suffix to be rgb. With suffix .raw, ImageMagick does not recognize it.

You 29x29 px raw file does not open for me. If I change it to rgb, then it opens but does not look correct. With a raw file, to read it, one must specify the size and depth. So something is wrong with your raw file or you have transparency or you have not specified the depth.

For example, I can take the ImageMagick internal logo: image and convert to raw (.rgb) as follows. The image is 640x480.

Code: Select all

convert logo: -depth 8 logo.rgb
The to convert it back

Code: Select all

convert -size 640x480 -depth 8 logo.rgb logo.png
works fine for me.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert image (.jpg) to .raw (in php)

Post by fmw42 »

Post your original jpg or png avatar image, so I can try converting it to .rgb and then convert it back again.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert image (.jpg) to .raw (in php)

Post by fmw42 »

It also looks like you have interleaved the file. Try without interleaving.
elliot.
Posts: 7
Joined: 2017-12-18T08:52:29-07:00
Authentication code: 1152

Re: convert image (.jpg) to .raw (in php)

Post by elliot. »

http://singularity.wtf/test/avatar.png <- original
http://singularity.wtf/test/avatar.raw <- photoshop generated
http://singularity.wtf/test/avatar.rgb <- im generated

how the .raw from photoshop looks like ingame: (see first post for settings)
Image

how the .rgb from im looks like ingame: (convert avatar.png -alpha off -depth 8 avatar.rgb)
Image


thank you so much!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert image (.jpg) to .raw (in php)

Post by fmw42 »

I am confused. You say you want no transparency, but you have checked for the raw format to be transparent. You have also asked for it to be interleaved, which usually means interleaved by line rather than by plane.

These all work for me:

Normal:

Code: Select all

convert avatar.png -alpha off -depth 8 avatar1.rgb

convert -size 96x96 -depth 8 avatar.rgb avatar1.png
Interlaced by line

Code: Select all

convert avatar.png -alpha off -depth 8 -interlace line avatar2.rgb

convert -size 96x96 -depth 8 -interlace line avatar2.rgb avatar2.png
Normal with alpha

Code: Select all

convert avatar.png -depth 8 avatar3.rgba

convert -size 96x96 -depth 8 avatar3.rgba avatar3.png

I do not know what your other software needs to work correctly nor do I know what format Photoshop uses for .raw.


P.S. GIMP does not recognize your file with .raw suffix. But if I change it to .rgba, then it finds it and can open it when I tell it the size and that it has alpha.
elliot.
Posts: 7
Joined: 2017-12-18T08:52:29-07:00
Authentication code: 1152

Re: convert image (.jpg) to .raw (in php) [8b/c, no alpha] help pls!

Post by elliot. »

the transparency checkbox is because i have other graphics with alpha transparency :)

ill try your cmds and report back here. thank you!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert image (.jpg) to .raw (in php) [8b/c, no alpha] help pls!

Post by fmw42 »

P.S. GIMP does not recognize your file with .raw suffix. But if I change it to .rgba, then it finds it and can open it when I tell it the size and that it has alpha.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert image (.jpg) to .raw (in php) [8b/c, no alpha] help pls!

Post by fmw42 »

elliot. wrote: 2017-12-18T13:25:18-07:00 the transparency checkbox is because i have other graphics with alpha transparency :)

ill try your cmds and report back here. thank you!
The transparency check box is not to say that the input has transparency, but to save the output with transparency. If you do not want transparency in your output from PS, then do not check that check box. Also be sure you want interleaving. You may want to not use interleaving.

P.S. GIMP does not recognize your file with .raw suffix. But if I change it to .rgba, then it finds it and can open it when I tell it the size and that it has alpha.
elliot.
Posts: 7
Joined: 2017-12-18T08:52:29-07:00
Authentication code: 1152

Re: convert image (.jpg) to .raw (in php) [8b/c, no alpha] help pls!

Post by elliot. »

oh it gets interesting!
this are ingame screens:

convert avatar.png -alpha off -depth 8 -interlace line avatar.rgb
Image

convert avatar.png -alpha off -depth 8 -interlace line avatar2.rgba
Image

does that give u a hint whats wrong?

thanks in advance!
elliot.
Posts: 7
Joined: 2017-12-18T08:52:29-07:00
Authentication code: 1152

Re: convert image (.jpg) to .raw (in php) [8b/c, no alpha] help pls!

Post by elliot. »

convert avatar.png -alpha off -depth 8 -interlace none avatar2.rgba
did the job!!

can u help with php im calls too?

thank you so much :-*
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert image (.jpg) to .raw (in php) [8b/c, no alpha] help pls!

Post by fmw42 »

Sorry, I do not know the PHP Imagick calls. You can use PHP exec() and just put in your ImageMagick command line.
Post Reply