By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,846 Members | 1,211 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,846 IT Pros & Developers. It's quick & easy.

Image Resize & Rotation

P: 34
Image Resize & Rotation

Hi

I have 2 scripts, one for Image rotation and other image resize and they both are working.

Image resize scripts load the picture and resize it and Image rotation rotate the image by 90 deg. They are two differennt files i.e. resize.php and rotate.php.

What I want to do is to combine both rotate.php & resize.php files, so when the script resized the image than it will call rotate script to rotate the image and display it on the screen.. I hope I am making sence.. I am finding hard to explain.. If u dont understand anything please let me know..
*************************
Code for rotate.php
[php]<?php
// File and rotation
$filename = 'image.png';
$degrees = 18;

// Content type
header('Content-type: image/png');

// Load
$source = imagecreatefrompng($filename);

// Rotate
$rotate = imagerotate($source, $degrees, 0);

// Output
imagepng($rotate);
?>
============================
Code for resize.php
<?php
$src_img = imagecreatefrompng('image.png');
$srcsize = getimagesize('image.png');
$dest_x = 200;
$dest_y = (200 / $srcsize[0]) * $srcsize[1];
$dst_img = imagecreatetruecolor($dest_x, $dest_y);
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0,
$dest_x, $dest_y, $srcsize[0], $srcsize[1]);
header("content-type: image/png");
imagepng($dst_img);
imagedestroy($src_img);
imagedestroy($dst_img);
?>[/php]thanks

Please enclose any code within the proper code tags. See the Posting Guidelines on how to do that.

moderator
Mar 5 '08 #1
Share this Question
Share on Google+
7 Replies


hsriat
Expert 100+
P: 1,654
Don't output $rotate and use it as:
$src_img = $rotate;
Mar 5 '08 #2

P: 34
Don't output $rotate and use it as:
$src_img = $rotate;
well i changed the output "$src_img = $rotate;" but it still did not work... Just to let know there are two different files

File 1 is reseize.php

File 2 is rotate.php

thanks
Mar 7 '08 #3

hsriat
Expert 100+
P: 1,654
[php]<?php
$src_img = imagecreatefrompng('image.png');
$srcsize = getimagesize('image.png');
$dest_x = 200;
$dest_y = (200 / $srcsize[0]) * $srcsize[1];
$dst_img = imagecreatetruecolor($dest_x, $dest_y);
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dest_x, $dest_y, $srcsize[0], $srcsize[1]);
imagedestroy($src_img);

//header("content-type: image/png");
//imagepng($dst_img);
//?><?php
// File and rotation
//$filename = 'image.png';
$degrees = 18;

// Load
//$source = imagecreatefrompng($filename);

// Rotate
$rotate = imagerotate($dst_img, $degrees, 0); //CHANGED
imagedestroy($dst_img);

// Content type
header('Content-type: image/png');

// Output
imagepng($rotate);
imagedestroy($rotate);
?>[/php]
See if this works.
Mar 7 '08 #4

P: 34
[php]<?php
$src_img = imagecreatefrompng('image.png');
$srcsize = getimagesize('image.png');
$dest_x = 200;
$dest_y = (200 / $srcsize[0]) * $srcsize[1];
$dst_img = imagecreatetruecolor($dest_x, $dest_y);
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dest_x, $dest_y, $srcsize[0], $srcsize[1]);
imagedestroy($src_img);

//header("content-type: image/png");
//imagepng($dst_img);
//?><?php
// File and rotation
//$filename = 'image.png';
$degrees = 18;

// Load
//$source = imagecreatefrompng($filename);

// Rotate
$rotate = imagerotate($dst_img, $degrees, 0); //CHANGED
imagedestroy($dst_img);

// Content type
header('Content-type: image/png');

// Output
imagepng($rotate);
imagedestroy($rotate);
?>[/php]
See if this works.

A BIG Thanks to You.. I was working on this from last week.. Thanks very much.. Just one more question.. If I want to resize and rotate .jpg file, so I just replaced .png with .jpg, gif and so on.

Thanks
Mar 7 '08 #5

hsriat
Expert 100+
P: 1,654
A BIG Thanks to You.. I was working on this from last week.. Thanks very much..
You are welcome.
Just one more question.. If I want to resize and rotate .jpg file, so I just replaced .png with .jpg, gif and so on.
No, it won't work. You will have to first check which image it is, then apply the corrosponding imagecreatefromXXX() function.
[php]<?php
$srcsize = getimagesize('image.png');
switch ($srcsize[mime])
{
case ('image/gif'):
$src_img = imagecreatefromgif('image.gif');
break;
case ('image/png'):
$src_img = imagecreatefrompng('image.png');
break;
case ('image/jpeg'):
$src_img = imagecreatefromjpeg('image.jpg');
break;
default:
return;
}[/php]
* make sure if its imagecreatefromjpeg or imagecreatefromjpg
Mar 7 '08 #6

P: 34
You are welcome.

No, it won't work. You will have to first check which image it is, then apply the corrosponding imagecreatefromXXX() function.
[php]<?php
$srcsize = getimagesize('image.png');
switch ($srcsize[mime])
{
case ('image/gif'):
$src_img = imagecreatefromgif('image.gif');
break;
case ('image/png'):
$src_img = imagecreatefrompng('image.png');
break;
case ('image/jpeg'):
$src_img = imagecreatefromjpeg('image.jpg');
break;
default:
return;
}[/php]
* make sure if its imagecreatefromjpeg or imagecreatefromjpg
once again thank you.. i will give it a go
Mar 7 '08 #7

P: 34
once again thank you.. i will give it a go
Thanks for all your help

Regards

InfoSeekar
Mar 10 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.