Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

PROBLEM WITH CROP IMAGE

Links for php scripts

Moderators: macek, egami, gesf

PROBLEM WITH CROP IMAGE

Postby Geethu » Thu Jun 14, 2012 2:42 am

Hi,
I am a beginner in php and i am trying to crop an image.But not getting cropped output
steps i did:
1. uploaded an image using php to a Database.
2. on click on of crop link it taakes me to new page crop_img.php
3.here i have used jcrop ( but not working)
:help:
code:


if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
if($_GET['id'])
{
$lid=$_GET['id'];
unlink($lid);
}

$image=mysql_query("SELECT * from image where id=$lid");

$targ_w = $targ_h = 150;
$jpeg_quality = 90;
$img= '<img src=get_crop.php?id=$lid />'; //feel error is here//
$img_r = imagecreatefromjpeg($img);
$dst_r = ImageCreateTrueColor( $targ_w, $targ_h );

imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],
$targ_w,$targ_h,$_POST['w'],$_POST['h']);

header('Content-type: image/jpeg');
imagejpeg($dst_r,null,$jpeg_quality);
exit;
}?>


// form inside body//
<form action="crop_img.php" method="post" onsubmit="return checkCoords();">
<input type="hidden" id="x" name="x" />
<input type="hidden" id="y" name="y" />
<input type="hidden" id="w" name="w" />
<input type="hidden" id="h" name="h" />
<input type="submit" value="Crop Image" />
</form>

please help
Geethu
New php-forum User
New php-forum User
 
Posts: 2
Joined: Thu Jun 14, 2012 2:16 am

Re: PROBLEM WITH CROP IMAGE

Postby ejsexton82 » Thu Jun 14, 2012 8:06 pm

The imagecreatefromjpeg() requires the file name of a local JPEG file as its parameter:

Code: Select all
$image = imagecreatefromjpeg('../local/file.jpg');


The easiest solution might be to copy the code from get_crop.php and use the imagecreatefromstring() function:

Code: Select all
// get_crop.php code goes here
$image = imagecreatefromstring($imageStringFromGetCropPHPCode);


A more complex, less efficient solution would be to try to use cURL to retrieve the image from get_crop.php:

Code: Select all
// Retrieve the image string using cURL
$ch = curl_init("http://www.example.url/get_crop.php?id={$lid}");
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$imageString = curl_exec($ch);
curl_close($ch);

// Process the image string
$image = imagecreatefromstring($imageString);


I hope that helps. Good luck!

Sources:
User avatar
ejsexton82
New php-forum User
New php-forum User
 
Posts: 86
Joined: Mon Jun 04, 2012 10:05 pm
Location: Ankara, Turkey

Re: PROBLEM WITH CROP IMAGE

Postby Geethu » Fri Jun 15, 2012 2:06 am

thanks ejsexton82
imagecreatefromstring() worked :)
Geethu
New php-forum User
New php-forum User
 
Posts: 2
Joined: Thu Jun 14, 2012 2:16 am


Return to PHP Scripts

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.