467,908 Members | 1,851 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,908 developers. It's quick & easy.

Image Resize & Rotation

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
  • viewed: 8547
Share:
8 Replies
hsriat
Expert 1GB
Don't output $rotate and use it as:
$src_img = $rotate;
Mar 5 '08 #2
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 1GB
[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
[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 1GB
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
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
once again thank you.. i will give it a go
Thanks for all your help

Regards

InfoSeekar
Mar 10 '08 #8
Thank you very much for your post hsriat, it's just what the doctor ordered! I know that it's years after the fact, but just wanted to say thanks :)
Jul 17 '20 #9

Post your reply

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

Similar topics

21 posts views Thread by Nik Coughlin | last post: by
17 posts views Thread by santel_helvis | last post: by
5 posts views Thread by Ricardo Furtado | last post: by
2 posts views Thread by Dominic Vella | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.