473,772 Members | 3,712 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Image Resize & Rotation

34 New Member
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 = imagecreatefrom png($filename);

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

// Output
imagepng($rotat e);
?>
=============== =============
Code for resize.php
<?php
$src_img = imagecreatefrom png('image.png' );
$srcsize = getimagesize('i mage.png');
$dest_x = 200;
$dest_y = (200 / $srcsize[0]) * $srcsize[1];
$dst_img = imagecreatetrue color($dest_x, $dest_y);
imagecopyresamp led($dst_img, $src_img, 0, 0, 0, 0,
$dest_x, $dest_y, $srcsize[0], $srcsize[1]);
header("content-type: image/png");
imagepng($dst_i mg);
imagedestroy($s rc_img);
imagedestroy($d st_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 9429
hsriat
1,654 Recognized Expert Top Contributor
Don't output $rotate and use it as:
$src_img = $rotate;
Mar 5 '08 #2
infoseekar
34 New Member
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 Recognized Expert Top Contributor
[php]<?php
$src_img = imagecreatefrom png('image.png' );
$srcsize = getimagesize('i mage.png');
$dest_x = 200;
$dest_y = (200 / $srcsize[0]) * $srcsize[1];
$dst_img = imagecreatetrue color($dest_x, $dest_y);
imagecopyresamp led($dst_img, $src_img, 0, 0, 0, 0, $dest_x, $dest_y, $srcsize[0], $srcsize[1]);
imagedestroy($s rc_img);

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

// Load
//$source = imagecreatefrom png($filename);

// Rotate
$rotate = imagerotate($ds t_img, $degrees, 0); //CHANGED
imagedestroy($d st_img);

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

// Output
imagepng($rotat e);
imagedestroy($r otate);
?>[/php]
See if this works.
Mar 7 '08 #4
infoseekar
34 New Member
[php]<?php
$src_img = imagecreatefrom png('image.png' );
$srcsize = getimagesize('i mage.png');
$dest_x = 200;
$dest_y = (200 / $srcsize[0]) * $srcsize[1];
$dst_img = imagecreatetrue color($dest_x, $dest_y);
imagecopyresamp led($dst_img, $src_img, 0, 0, 0, 0, $dest_x, $dest_y, $srcsize[0], $srcsize[1]);
imagedestroy($s rc_img);

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

// Load
//$source = imagecreatefrom png($filename);

// Rotate
$rotate = imagerotate($ds t_img, $degrees, 0); //CHANGED
imagedestroy($d st_img);

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

// Output
imagepng($rotat e);
imagedestroy($r otate);
?>[/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 Recognized Expert Top Contributor
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 imagecreatefrom XXX() function.
[php]<?php
$srcsize = getimagesize('i mage.png');
switch ($srcsize[mime])
{
case ('image/gif'):
$src_img = imagecreatefrom gif('image.gif' );
break;
case ('image/png'):
$src_img = imagecreatefrom png('image.png' );
break;
case ('image/jpeg'):
$src_img = imagecreatefrom jpeg('image.jpg ');
break;
default:
return;
}[/php]
* make sure if its imagecreatefrom jpeg or imagecreatefrom jpg
Mar 7 '08 #6
infoseekar
34 New Member
You are welcome.

No, it won't work. You will have to first check which image it is, then apply the corrosponding imagecreatefrom XXX() function.
[php]<?php
$srcsize = getimagesize('i mage.png');
switch ($srcsize[mime])
{
case ('image/gif'):
$src_img = imagecreatefrom gif('image.gif' );
break;
case ('image/png'):
$src_img = imagecreatefrom png('image.png' );
break;
case ('image/jpeg'):
$src_img = imagecreatefrom jpeg('image.jpg ');
break;
default:
return;
}[/php]
* make sure if its imagecreatefrom jpeg or imagecreatefrom jpg
once again thank you.. i will give it a go
Mar 7 '08 #7
infoseekar
34 New Member
once again thank you.. i will give it a go
Thanks for all your help

Regards

InfoSeekar
Mar 10 '08 #8
djmcfar
1 New Member
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
8504
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 top-down scrolling game. Or would I be better off preprocessing all of the images with something server side such as PHP and then preloading them into my JavaScript already manipulated? The only thing I don't like about the idea of...
15
5363
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 path of the uploaded image, and resize it with the provided dimensions. My function is below. The current function is returning an error when run from the upload function: A generic error occurred in GDI+. Not sure what exactly that means. From what...
17
29416
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
2301
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 placed around the ball and which one of those images is displayed. Each pool cue image is in a slightly different orientation and the correct one is chosen to match the orientation of the cursor around the ball. Holding down the left mouse button...
2
19376
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 (height) x 780 (wide) So the "preferred size" would be 440 x 780
4
2372
by: joe | last post by:
how to resize an upload image and then change to binary & insert to db
5
2550
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: http://vb-helper.com/index_vbnet.html but the problem is that the image doesn't stay at the top, instead, the image is created upon another bitmap, even larger, and at its right corner. I've already tryed to cut the right corner, with the right...
7
17058
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 = "photo/thumbs/"; // Path To Thumbnails Directory $twidth = "125"; // Maximum Width For Thumbnail Images
2
20909
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 would be appreciated. I've been trying numerous ways to resize images, as I want to make store thumbnails, not full images in my database. -----------------------------------------------------------------------------
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10261
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8934
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6715
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.