Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: PHP: Image Editing  (Read 1940 times)

0 Members and 1 Guest are viewing this topic.
PHP: Image Editing
« on: March 15, 2007, 10:06:07 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 563
I have looked into making images/editing images using PHP and found out about the GD libraries and I still cant find much help in the area I wanted it in.

I need to know how to display a row of same size images (like tiles) each named 1.png to 10.png, so I'd    imagine there was some way of opening an image and pasting it into a part of the created image at a certain x and y coordinate?

Any help would be much appreciated, thanks :)

[edit]

Would I have to use a loop and use these always:
Code: [Select]
<?php
$img ImageCreate(480,48) or die ("Cannot Create image");
$count 1;
while ($count <= 10)
{
$tile imagecreatefrompng(&#39;images/&#39;.$count.&#39;.png&#39;);
imagesettile($img$tile);
imagefilledrectangle($img, (($count-1)*48), 0, ((($count-1)*48)+48), 48IMG_COLOR_TILED);
$count++;
}
header("Content-type: image/png");
ImagePng($img);
imageDestroy($img);
?>


I'm not even sure if you can do that.. but just an idea I cant try it right now as I'm going very soon.
« Last Edit: March 21, 2007, 05:16:41 pm by Benito »
Logged

I ♥ Open Girlfriend (What!? I didn't add this.. must have been Solly!)
  • My DevArt Account

PoeFacedKilla

Prussian Killer Bee
Re: PHP: Image Editing
« Reply #1 on: March 16, 2007, 03:25:36 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 269
« Last Edit: March 18, 2007, 01:43:28 am by Madilim Kagalakan »
Logged
the Indyboard - User Generated Social Forum | Now With Even More Discussion!
Poe, The Independent Programmer
  • Zelda Shrine

Dayjo

shut the fuck up donny.
Re: PHP: Image Editing
« Reply #2 on: March 16, 2007, 03:59:04 pm »
  • hungry..
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3602
Try using the imagecopy() function to copy part of one image onto a new one.


This is semi-pseudo code.. i've not tested so it probably wont work, but hopefully you'll get the idea.
Code: [Select]
<?php
header("Content-type: image/png");

$img imagecreate(480,48) or die ("Cannot Create image");
$count 1;
while ($count 10)
{
$tile imagecreatefrompng(&#39;images/&#39;.$count.&#39;.png&#39;);
imagecopy($img,$tile,($count-1)*48,0,0,0,48,48);
$count++;
}

imagepng($img);
imagedestroy($img);
?>
« Last Edit: March 16, 2007, 04:01:34 pm by Dayjo »
Logged
  • My Blog
Re: PHP: Image Editing
« Reply #3 on: March 19, 2007, 10:09:59 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 563
Try using the imagecopy() function to copy part of one image onto a new one.


This is semi-pseudo code.. i've not tested so it probably wont work, but hopefully you'll get the idea.
Code: [Select]
<?php
header("Content-type: image/png");

$img imagecreate(480,48) or die ("Cannot Create image");
$count 1;
while ($count 10)
{
$tile imagecreatefrompng(&#39;images/&#39;.$count.&#39;.png&#39;);
imagecopy($img,$tile,($count-1)*48,0,0,0,48,48);
$count++;
}

imagepng($img);
imagedestroy($img);
?>

Indeed seems to work, I've started to do slightly more complicated things now :).

Got another question though, bits of my little images are transparent yet the BG is all black instead ???

How do I fix this?
Logged

I ♥ Open Girlfriend (What!? I didn't add this.. must have been Solly!)
  • My DevArt Account
Re: PHP: Image Editing, NEW QUESTION
« Reply #4 on: March 19, 2007, 11:20:09 pm »
  • Minalien
  • *
  • Reputation: +10/-1
  • Offline Offline
  • Gender: Female
  • Posts: 2119
I'm not sure exactly what it was, but I started doing some GD Library stuff recently, and you have to set a transparent color, check the php.net documentation
Logged
Quote
There's such a double standard about religion in the modern world. Catholics can gather, wear white robes, and say "In nomine Patris, et Filii, et Spiritus Sancti" and be considered normal.

But if my friends and I gather, wear black robes, and say  "Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn", we're considered cultists.
  • Development Blog
Re: PHP: Image Editing, NEW QUESTION
« Reply #5 on: March 20, 2007, 07:34:22 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 563
I'm not sure exactly what it was, but I started doing some GD Library stuff recently, and you have to set a transparent color, check the php.net documentation

Hmm thats annoying, it recognises when images overlap its just the very background.. even alpha transparencies work with images that overlap... just as said the areas where things are transparent and there are no images its black...
Logged

I ♥ Open Girlfriend (What!? I didn't add this.. must have been Solly!)
  • My DevArt Account
Re: PHP: Image Editing, NEW QUESTION
« Reply #6 on: March 21, 2007, 12:29:36 pm »
  • Minalien
  • *
  • Reputation: +10/-1
  • Offline Offline
  • Gender: Female
  • Posts: 2119
Here's how I had done it:

Code: [Select]
<?php
header( &#39;Content-Type: image/png&#39; );

$TheImage imagecreate240160 );
$Link imagecreatefrompng( &#39;Link.png&#39; );

$BGColor imagecolorallocate$TheImage2550255 );

imagefill$TheImage00$BGColor );

imagecopy$TheImage$Link3224003232 );

imagecolortransparent$TheImage$BGColor );

imagejpeg$TheImage );

imagedestroy$TheImage );
?>


made a proper transparent file for me o_O

http://us2.php.net/manual/en/ref.image.php
There are some alpha functions on there, see if you can figure it out from there, I cant do anything here at school ;/
Logged
Quote
There's such a double standard about religion in the modern world. Catholics can gather, wear white robes, and say "In nomine Patris, et Filii, et Spiritus Sancti" and be considered normal.

But if my friends and I gather, wear black robes, and say  "Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn", we're considered cultists.
  • Development Blog
Re: PHP: Image Editing, NEW QUESTION
« Reply #7 on: March 21, 2007, 05:16:17 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 563
Ah filling the image with a background colour then setting that to transparent worked a treat :D thanks :D.
Logged

I ♥ Open Girlfriend (What!? I didn't add this.. must have been Solly!)
  • My DevArt Account
Re: PHP: Image Editing, NEW QUESTION
« Reply #8 on: March 22, 2007, 06:11:07 pm »
  • IBV
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Female
  • Posts: 1075
Ah filling the image with a background colour then setting that to transparent worked a treat :D thanks :D.

You should also be able to change the GD library's color-depth to 32-bits. That way you can also load in a 32-bit PNG which uses the last 8 bits (alpha-channel) to specify transparency. Because if it is set to 24-bit (probably default, not sure), it will ignore that alpha channel (transparency), so that could be your problem.
Logged
My signature is empty.
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.054 seconds with 55 queries.

anything