Closed Thread Icon

Topic awaiting preservation: is anyone here familiar with gd image library and jpg functions in php? (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12917" title="Pages that link to Topic awaiting preservation: is anyone here familiar with gd image library and jpg functions in php? (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: is anyone here familiar with gd image library and jpg functions in php? <span class="small">(Page 1 of 1)</span>\

 
smonkey
Paranoid (IV) Inmate

From: Northumberland, England
Insane since: Apr 2003

posted posted 10-06-2003 00:35

hi,

I have many images that I want to dice up, I'm hoping to do it in photoshop http://www.ozoneasylum.com/Forum3/HTML/003725.html , although I'm also looking at other ways to do it as I need the result quickly and need to pick your guys brains asap.

Can the same sort of thing be accomplished relatively easily with php? If so then I would love some help with it, I have php set up locally so I'll just run the script as an image processor.

Please help if you can,

Thank you once again guys,

Jon

Gweilo
Bipolar (III) Inmate

From: switzerland
Insane since: Sep 2002

posted posted 10-06-2003 10:06

Yes, it is possible. Here's how I would do it:

code:
function cutit($imgsrc, $width, $height){
$image = imagecreatefromjpeg($imgsrc);
$size_arr = getimagesize($imgsrc);
$img_width=$size_arr[0];
$img_height=$size_arr[1];

for ($i=0; $i<$img_width; $i+=$width)
{
for ($j=0; $j<$img_height; $j+=$height)
{
$image1 = imagecreate($width,$height);
ImageCopy($image1,$image,0,0,$i,$j,$width,$height);
$imagename = substr($imgsrc,0,-3).$i."-".$j.".jpg";
imagegif($imagename,100);
}
}
}

cutit("yourimage.jpg");


I didn't test it, so with a little bugfixing it might work.

[This message has been edited by Gweilo (edited 10-17-2003).]

smonkey
Paranoid (IV) Inmate

From: Northumberland, England
Insane since: Apr 2003

posted posted 10-06-2003 15:37

Thanks mate,

Now people who have seen my posts before may well know I know practically nothing. I have tried your code using my own image and it doesn't work as intended but it's odd.

Whereas I would expect to see an error message or nothing at all I get all the php code appearing in the page as if it were just a simple html doc, nothing seems to run - so I tried putting it <? ?> tags thinking that maybe I was dumb and they were needed in .php files without html.

This then seemed to be doing something, but ever couple of seconds windows would pop up an alert saying apache.exe had generated errors and needed to close but then it wouldn't close (status monitor has it still running).

So I did the basic looking for missing ; characters or typos and couldn't spot any - so what is up? I'm sure I'm more than likely doing something wrong, not sure what tho.

Also if it is of any importance, I think i'd like to be able to slice up the big images sent to the script into 10px X 10px squares.

Sorry to ask, but any further help would be a huge help,

Jon

P.S. what is 'imagegif()'? I thought GD didn't make gifs? I'm confused.

[This message has been edited by smonkey (edited 10-06-2003).]

Gweilo
Bipolar (III) Inmate

From: switzerland
Insane since: Sep 2002

posted posted 10-06-2003 16:57

hey,

yeah. should have been imagejpeg instead of imagegif =)
And run the function like this:
cutit("yourimage.jpg",10,10);

I'll test it when I have time...

Gweilo

Gweilo
Bipolar (III) Inmate

From: switzerland
Insane since: Sep 2002

posted posted 10-06-2003 17:55
code:
<?PHP
function cutit($imgsrc, $width, $height)
{
$imgs = 0;
$image = imagecreatefromjpeg($imgsrc);
$size_arr = getimagesize($imgsrc);
$img_width=$size_arr[0];
$img_height=$size_arr[1];
for ($j=0; $j<$img_height; $j+=$height)
{
for ($i=0; $i<$img_width; $i+=$width)
{
if ($i+$width >= $img_width)
$temp_width = $img_width-$i; // if right border is reached
else
$temp_width = $width;
if ($j+$height >= $img_height)
$temp_height = $img_height-$j; // if bottom border is reached
else
$temp_height = $height;
$image1 = imagecreatetruecolor($temp_width,$temp_height);
ImageCopy($image1,$image,0,0,$i,$j,$temp_width,$temp_height);
$imagename = substr($imgsrc,0,-4)."-".($i/$width)."-".($j/$width).".jpg";
$ok = imagejpeg($image1,$imagename,100);
if ($ok)
$imgs++;
// take this out, if you want to render it faster
echo "<img src=\"".$imagename."\" />";
}
}
return $imgs;
}
// first param = image file path
// second param = width of new images in pixels
// third param = height of new images in pixels
$imgs = cutit("hall.jpg",10,10);
echo "<br />".$imgs." images created!";
?>



This time I tested it =) and it works just fine.

smonkey
Paranoid (IV) Inmate

From: Northumberland, England
Insane since: Apr 2003

posted posted 10-06-2003 23:02

thanks buddy - you are a star,

I'll post the finished thing when i'm done - it isn't anything really advanced or anything, just a weird image switching thing, but just so you know why i needed your help.

thanks again,

jon

Gweilo
Bipolar (III) Inmate

From: switzerland
Insane since: Sep 2002

posted posted 10-06-2003 23:08

Glad to help!
I was asking myself what this could be good for.
I would definitely like to see the result.

smonkey
Paranoid (IV) Inmate

From: Northumberland, England
Insane since: Apr 2003

posted posted 11-03-2003 14:21

here's what i needed the slices for:
http://www.ozoneasylum.com/Forum2/HTML/002429.html - the url is in a post near the end, any javascript help would be much appreciated.

Thanks,

Jon

visit my CryoKinesis Online Gallery

« BackwardsOnwards »

Show Forum Drop Down Menu