Connecting Tech Pros Worldwide Forums | Help | Site Map

How do you zoom in on an image using PHP?

comp.lang.php
Guest
 
Posts: n/a
#1: May 4 '06
re: http://www.phpbuilder.com/columns/pablo19990729.php3

I tried recreating his code (with some modernity considering he's using
PHP 3 and I'm using PHP 4.3.2 - PHP 5.0.4):

[PHP]
<?
if ($_POST['blah']) {
list($image_width, $image_height) =
@getimagesize('http://valsignalandet.com/images/stave.jpg');
$zoomImgObj =
@imagecreatefromjpeg('http://valsignalandet.com/images/stave.jpg');
$imageObj = @imagecreatetruecolor($image_width, $image_height);
$factor=3.75;
$posx = floor($_POST['val_x'] * $factor - floor((int)($image_width /
2)));
$posy = floor($_POST['val_y'] * $factor - floor((int)($image_height /
2)));
$copia = @imagecopyresized($zoomImgObj, $imageObj, 0, 0, $posx,
$posy, $image_width, $image_height, $image_width, $image_height);
@imagejpeg($imageObj, '/tmp/val.jpg');
@imagedestroy($imageObj);
@imagedestroy($zoomImgObj);
$contents = @file_get_contents('/tmp/val.jpg');

require_once('/var/www/html/tools/tools_globals/client_globals.inc.php');

require_once('/var/www/html/tools/ivc/ivc_globals/project_globals.inc.php');
require_once('/var/www/html/tools/ivc/include/classes.inc.php');
require_once('/var/www/html/tools/ivc/include/db_action.inc.php');
DownloadGenerator::generateForceDownloadHeaders('/tmp/val.jpg',
$contents);
} else {

?>
<html>
<head>
<title>asdf</title>
</head>
<body>
<form method="post" action="<?= $_SERVER['PHP_SELF'] ?>">
<input type="hidden" id="blah" name="blah" value="foo">
<input type="image" id="val" name="val"
src="http://valsignalandet.com/images/stave.jpg"
alt="V&auml;lsignalandet" value="val">
</form>
</body>
</html>
<? } ?>
[/PHP]

However, each time I run this script, the resulting downloaded "image"
is a black graphic, same width and height as the original image.

What I want is the ability to zoom in on an image based upon the place
where the user clicks (thus capturing the positions via $_POST)

Any suggestions?

Thanx
Phil


comp.lang.php
Guest
 
Posts: n/a
#2: May 5 '06

re: How do you zoom in on an image using PHP?



comp.lang.php wrote:[color=blue]
> re: http://www.phpbuilder.com/columns/pablo19990729.php3
>
> I tried recreating his code (with some modernity considering he's using
> PHP 3 and I'm using PHP 4.3.2 - PHP 5.0.4):
>
> [PHP]
> <?
> if ($_POST['blah']) {
> list($image_width, $image_height) =
> @getimagesize('http://valsignalandet.com/images/stave.jpg');
> $zoomImgObj =
> @imagecreatefromjpeg('http://valsignalandet.com/images/stave.jpg');
> $imageObj = @imagecreatetruecolor($image_width, $image_height);
> $factor=3.75;
> $posx = floor($_POST['val_x'] * $factor - floor((int)($image_width /
> 2)));
> $posy = floor($_POST['val_y'] * $factor - floor((int)($image_height /
> 2)));[/color]

[snip]

UPDATE:

I think this is the culprit, because if I click on the upper left hand
corner of the image, I get something LIKE a zoomed-in image but
terribly offset, otherwise, nuthin' but black:

[PHP]
$factor=3.75;
$posx = floor($_POST['val_x'] * $factor - (int)($image_width / 2));
$posy = floor($_POST['val_y'] * $factor - (int)($image_height / 2));
[/PHP]

I suspect the calculations for $posx and $posy are causing it to
happen.. but I don't have any idea how to fix that.

Phil

Closed Thread