Jump to content

crop and upload image


Isset1988

Recommended Posts

Hello guys,

 

I want to crop an image hi.png/.gif/.jpg which is on the root folder, after that i want auto upload it to the root/images folder.

 

I use the above code but i dont have any results. Can you help me?  :confused: :confused: :confused:

 

$src = imagecreatefrompng('hi.png'); 
$dest = imagecreatetruecolor(648,432); 
imagecopy($dest, $src, 0, 0, 20, 13, 80, 40); 

Link to comment
Share on other sites

I Follow your instruction in my custom php page.

 

The result is this:

10p0leq.jpg

 

The code is:

<?php

$old_image='hi.gif';
$full_old='hi.gif';
$full_new='hey.jpg';

$ext = pathinfo($full_old, PATHINFO_EXTENSION);
$ext = strtolower($ext);

$width=648;
$height=432;
$x=250;
$y=50;

$canvas = imagecreatetruecolor( $width, $height );

/* Create a new image in the memory from the file  according to file type */
/* IF you add more file types, be sure to add them to the switch statement */
switch ($ext) {
	case "jpg":
	case "jpeg":
		$cropped = imagecreatefromjpeg( $old_image );
		break;
	case "gif":
		$cropped = imagecreatefromgif( $old_image );
		break;
	case "png":
		$cropped = imagecreatefrompng( $old_image );
		break;
	default:
		exit();
		break;
}
/* create the cropped image */
imagecopy( $canvas, $cropped, 0,0, $x, $y, $size[0], $size[1]);
// Save the cropped image as cropped.jpg
imagejpeg( $canvas, $full_new, 100 );

?>

 

Can anyone help me?  :confused:

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.