convert image (.jpg) to .raw (in php) [8b/c, no alpha] help pls!
convert image (.jpg) to .raw (in php) [8b/c, no alpha] help pls!
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
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!!
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
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.
Re: convert image (.jpg) to .raw (in php)
i tried "convert avatar.jpg -alpha off avatar.raw"
with the same result...
with the same result...
- 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)
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?
should work. Note the suffix is . rgb not .raw
What is your IM version and platform, since syntax may vary.
Code: Select all
convert image.jpg image.rgb
What is your IM version and platform, since syntax may vary.
Re: convert image (.jpg) to .raw (in php)
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).
here is the error it produces:
green is the 29x29 avatar i linked u above.
red is another, bigger avatar converted with imagemagick.
best regards
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).
running system is ubuntu 14.04.Version: ImageMagick 6.7.7-10 2017-07-31 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP
here is the error it produces:
green is the 29x29 avatar i linked u above.
red is another, bigger avatar converted with imagemagick.
best regards
- 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)
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
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.
The to convert it back
works fine for me.
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
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
Code: Select all
convert -size 640x480 -depth 8 logo.rgb logo.png
- 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 your original jpg or png avatar image, so I can try converting it to .rgb and then convert it back again.
- 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)
It also looks like you have interleaved the file. Try without interleaving.
Re: convert image (.jpg) to .raw (in php)
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)
how the .rgb from im looks like ingame: (convert avatar.png -alpha off -depth 8 avatar.rgb)
thank you so much!
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)
how the .rgb from im looks like ingame: (convert avatar.png -alpha off -depth 8 avatar.rgb)
thank you so much!
- 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)
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:
Interlaced by line
Normal with alpha
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.
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
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
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.
Re: convert image (.jpg) to .raw (in php) [8b/c, no alpha] help pls!
the transparency checkbox is because i have other graphics with alpha transparency
ill try your cmds and report back here. thank you!
ill try your cmds and report back here. thank you!
- 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!
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.
- 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!
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.
Re: convert image (.jpg) to .raw (in php) [8b/c, no alpha] help pls!
oh it gets interesting!
this are ingame screens:
convert avatar.png -alpha off -depth 8 -interlace line avatar.rgb
convert avatar.png -alpha off -depth 8 -interlace line avatar2.rgba
does that give u a hint whats wrong?
thanks in advance!
this are ingame screens:
convert avatar.png -alpha off -depth 8 -interlace line avatar.rgb
convert avatar.png -alpha off -depth 8 -interlace line avatar2.rgba
does that give u a hint whats wrong?
thanks in advance!
Re: convert image (.jpg) to .raw (in php) [8b/c, no alpha] help pls!
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 :-*
did the job!!
can u help with php im calls too?
thank you so much :-*
- 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!
Sorry, I do not know the PHP Imagick calls. You can use PHP exec() and just put in your ImageMagick command line.