Server image manipulation?

Community Forums/General Help/Server image manipulation?

Yahfree(Posted 2011) [#1]
Hey, lets say I have a image that is 3px by 3px(for a simple example). Is there a way that I can isolate 9 areas(each 1px by 1px), and build a new image by rearranging these squares into a new shape? Of course the real image wouldn't be 1px by 1px, but I would know the pixel location and size of each rectangular region

Let me show you a diagram:




Would something like php's GD library work for this? The image would be on my web server, I would know the dimensions, and I would know the dimensions of the new image

Last edited 2011


D4NM4N(Posted 2011) [#2]
A couple of 2dimensional uint[] arrays maybe? One bigger than the original (say 2-3x the size) do your shifting with the pixel orientation center-center and then clip the result into a new smaller array or an image/pixmap object.
-Or just use 2 images and using the same method as above, lock the buffers and read writefast the pixels directly to do your shifting (possibly faster?)

I am not really sure i understand what you are trying to do. Are you after some kind of algorythm or are you talking about storage? Plus what is it with the "half pixel" movement?

Last edited 2011


Yahfree(Posted 2011) [#3]
they're not going to be single pixels. I was going to rearrange an image(texture of a mesh) to show the front/back view of the mesh. The texture areas are rectangular

Last edited 2011


D4NM4N(Posted 2011) [#4]
Do you mean a UV map?

Eg:

http://patrickwolleb.subumbo.com/uv-mapping/


Yahfree(Posted 2011) [#5]
yeah, so can I do this with some server-side php stuff in 2d?

basically, I want to preview what a texture looks like on a known mesh(front and back view)

and I know where the front and back "uv coords" are on the image, so can I just build two new front and back images by rearranging these rectangles?

Last edited 2011


Derron(Posted 2011) [#6]
Take a look at
http://de3.php.net/manual/en/function.imagecopymerge.php


So your steps:

0. (Preparational thoughts)
- if you want to have a kind of online-preview, you have to save the image in a working directory as just uploaded pictures will get deleted after the "initial"-php-process is dying (script which receives upload exited)

1.
- receive image by "upload" : "$_FILES" in PHP
- receive "to change"-params in PHP too

- Copy it to a working directory if you have a sharedhoster with shared /tmp directory (else you will not have all necessary rights, linux base....)
You can check this by using "move_uploaded_file()"
If you are not allowed to "move", you have to open the image in PHP, and save it to your working directory, because then the image is "chown" to your PHP-UserId/you.
If you are able to work, and are not interested where you work with your image, you can just open it, modify it - and when saving remember yourself to change filename as you wont have access to the /tmp directory.

2. open it in PHP, remember, big images are hungry for ressources, so you may run into some php-limits (imagine 2048x2048 textures)

3. modify it by using "imagecopymerge", link at the top contains an example

4. output to client/save to disk/mail... /return it ;D



Should be enough I think.

bye
MB

Last edited 2011


Yahfree(Posted 2011) [#7]
Looks like it'll work. I'll check it out!


Yahfree(Posted 2011) [#8]
Seems to be the way to go. Question though: What is the first pixel on the image? 0,0 or 1,1? and the last bottom-right corner? WIDTH-1,HEIGHT-1 or just WIDTH,HEIGHT?


D4NM4N(Posted 2011) [#9]
Neither, UV map coords are just a reference they do not relate to pixels at all.

I suppose you could think of them as fractions of your overall texture regardless of resolution.

For examples:

-If you had a texture 64x64 and used a UV map on a plane of UV 0,0 - 0.5,0.5 then you will be seeing 32x32 of your texture.

-If you used a uv of .5,.5 - .75,.75 then you would be showing pixels 15,15 - 24,24 (or there abouts) assuming it is a 64x64 texture.

-If you used 0,0 - 2,2 then you would be seeing 2 repeats of your texture (assuming you have the repeat flag on, otherwise it will texture map 1/4 of your plane with 1 repeat.

What i reccommend is setting up a test project in blitz with 1 cube and a texture with a angled camera so you can see the faces. Then play around with all the flags like repeat, clamp etc and then fiddle with the cube's verts UV numbers. You will soon see how it works.

To get an acutal pixel position on a uvmap (assuming the texture is mapped 0,0-1,1) i guess you could use:
ie to get UV position of pixel 10,9 on the uvmap
float X=10;
float Y=9;
float UVX=(1.0/TextureWidth)*X;
float UVY=(1.0/TextureWidth)*Y;

Then create a texture with 4 different textures in all 4 quarters and see if you can map different faces to different textures. This is where it gets a little more tricky.

Last edited 2011


Yahfree(Posted 2011) [#10]
I'm pretty sure the imagemerge function works off of pixels, not uv coords?