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
https://forums.phpfreaks.com/topic/264497-crop-and-upload-image/
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:

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.