Q:

php crop image without upload it

//Your Image
$imgSrc = "image.jpg"; 

list($width, $height) = getimagesize($imgSrc);

$myImage = imagecreatefromjpeg($imgSrc); 

if ($width > $height) {  
    $y = 0; 
    $x = ($width - $height) / 2; 
    $smallestSide = $height; 
} else {  
    $x = 0;  
    $y = ($height - $width) / 2;
    $smallestSide = $width; 
} 

$thumbSize = 100; 
$thumb = imagecreatetruecolor($thumbSize, $thumbSize);
imagecopyresampled($thumb, $myImage, 0, 0, $x, $y, $thumbSize, $thumbSize, $smallestSide, $smallestSide);

//Output
imagejpeg($thumb);

PAGE REVIEW  :
<?php

$sql1 = mysql_query("SELECT * FROM images");
while($row_img = mysql_fetch_array($sql1)){
$img_url=$row_img['3']; ?>
        <img src="/<? echo $img_url; ?>"  />        
<?php } ?>

I want to use this code with while to view my photo from database.
my image name in db $imgSrc=$img_url; that is row name.
Thank you

A:

This will work
$url = "http://localhost/sample.jpg";

$src = file_get_contents($url);

$myImage = imagecreatefromstring($src); 

if ($width > $height) {  
 $y = 0; 
 $x = ($width - $height) / 2; 
 $smallestSide = $height; 
} else {  
 $x = 0;  
 $y = ($height - $width) / 2;
 $smallestSide = $width; 
} 

$thumbSize = 100; 

$thumb = imagecreatetruecolor($thumbSize, $thumbSize);

imagecopyresampled($thumb, $myImage, 0, 0, $x, $y, $thumbSize, $thumbSize, $smallestSide, $smallestSide);

header('Content-Type: image/jpeg');
imagejpeg($myImage);

