473,387 Members | 1,342 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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
8 9365
hsriat
1,654 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
1,654 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
1,654 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

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

Similar topics

21
by: Nik Coughlin | last post by:
Are there methods for manipulating images in JavaScript that would allow me to write functions to rotate, skew, mask and resize images (bitmaps)? The functions need to be fast enough for use in a...
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
17
by: santel_helvis | last post by:
Hi All, Could anyone tell me how to rotate the image in javascript. Which concepts I should concentrate to rotate the image
3
by: Mark Szlazak | last post by:
The following page simulates a pool cue and cue ball: http://members.aol.com/myscript/cue.html Mouse cursor position around the cue ball determines where a roll-over of 179 pool cue images is...
2
by: Farce Milverk | last post by:
Hi, I'm looking for an algorithm to resize an image of arbitrary size to a "fixed" / required width and height. For example, my application requires that images be no larger than 440 pixel...
4
by: joe | last post by:
how to resize an upload image and then change to binary & insert to db
5
by: Ricardo Furtado | last post by:
I'm trying, for a week or two, to create a procedure in order to rotate the image in any picturebox control in a cephalometry software. I've found a web site that shows how that can be done:...
7
by: mishrarajesh44 | last post by:
hii all Truly telling i hav got this code from net & i am finding error while running the code below.. code:- <?php $idir = "photo/"; // Path To Images Directory $tdir =...
2
by: Dominic Vella | last post by:
Hi, I know I seem to have the really complicated questions, but I guess that's why I'm here. This is a little verbose, only because I've been trying to crack this for a week now. Your help...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.