FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


How would I resize an image from this code?





The-Master
Well I have gotten a lot better at PHP but I do not know how to resize an image that you have the url for. Here is the code:

Code:
<?php
header("Content-type: image/jpeg");
$img_bg_loc = @$_GET['image'];
list($x, $y, $maxwidth) = array(0, 0, 0);
$fontsize = 30;
if(@$_GET['fontsize']) {
   $fontsize = $_GET['fontsize'];
}
$font = 'Halo.ttf';
$text = @$_GET['text'];

$im = imagecreatefromjpeg($img_bg_loc);;


$img_w = imagesx($im);
$px = ($img_w - 1 * strlen($text)) / 3;

$red = imagecolorallocate($im, 214, 40, 40);


$x = 0;
$y = 60;
imagefttext($im, $fontsize, 0, $x, $y, $red, $font, $text);

imagejpeg($im);
imagedestroy($im);
?>


Thanks Very Happy All I want to di is resize it to 400x600
Esch
You'll want to use the imagecopyresized() or imagecopyresampled() to copy the image from the source to a new image (that you must allocate as well) with your specified size in mind. You can find reference for these two functions here:

imagecopyresized(): http://us2.php.net/manual/en/function.imagecopyresized.php
imagecopyresampled(): http://us2.php.net/manual/en/function.imagecopyresampled.php

The difference between the two is that imagecopyresized() will just do a simple linear resize, which may look pixelated, but is faster than imagecopyresampled() (which actually blends intermediate pixels to make the image look nicer). In practice, the performance loss of imagecopyresampled() is entirely worth it over the ugly images generated from imagecopyresized() (which are on par with how browsers usually resize images).

Hopefully that'll help.
ritesh26
Here it the function which will resize ur image with new width and height.
Code:

unction copyImage($srcFile, $w, $h, $quality = 80)
{
    $tmpSrc     = pathinfo(strtolower($srcFile));
   // $tmpDest    = pathinfo(strtolower($destFile));
    $size       = getimagesize($srcFile);
    if ($tmpSrc['extension'] == "gif" || $tmpSrc['extension'] == "jpg")
    {
       //$destFile  = substr_replace($destFile, 'jpg', -3);
       $dest      = imagecreatetruecolor($w, $h);
       imageantialias($dest, TRUE);
    } elseif ($tmpSrc['extension'] == "png") {
       $dest = imagecreatetruecolor($w, $h);
       imageantialias($dest, TRUE);
    } else {
      return false;
    }
 
    switch($size[2])
    {
       case 1:       //GIF
   header ("content-type: image/gif");
           $src = imagecreatefromgif($srcFile);
           break;
       case 2:       //JPEG
   header ("content-type: image/jpeg");
           $src = imagecreatefromjpeg($srcFile);
           break;
       case 3:       //PNG
        header ("content-type: image/png");
           $src = imagecreatefrompng($srcFile);
           break;
       default:
           return false;
           break;
    }
    imagecopyresampled($dest, $src, 0, 0, 0, 0, $w, $h, $size[0], $size[1]);
    switch($size[2])
    {
       case 1:
     imagegif ($dest);
        break;
       case 2:
           imagejpeg($dest,'', $quality);
           break;
       case 3:
           imagepng($dest);
    }
 imagedestroy ($dest);
 //imagedestroy ($sourceimg);
 //echo $destFile;
    //return $destFile;
}
The-Master
I tried this but this is what happened:
http://www.dougie.frih.net/PHP/before2.php?image=http://media.scout.com/Media/HS_Football/40585_GCruse.JPG

How do I make the image expand to the width and hight. Also ritesh26 I have not tried your code but it looks quite over complicated...

The reason I am trying to do this is too manage to get text the same size on resized images.
ritesh26
To use this code :
1- create a file image.php and write these code .
2- write these line in that file
image.php

Code:

createThumbnail($QUERY_STRING);

function createThumbnail($srcFile, $new_w=425,$new_h=60, $quality = 75){
     // Previous code which i have submitted
}


3 - now use this file where you want to resize the image

Code:

<img src="image.php?<?$image?>" >


Hope this will help you better.
Related topics
751 Useful Windows XP Files
XeononyX - online - forum and software
Picture resizing software :?:
How to create a php files that contain a image ?
Could someone help me with this image code
Create,Resize,Thumb, Shadow of your Images
Image not showing
Resize image in PNG Problem
Help with Css to insert image
random image code?
PHP Image crop
How to resizer you images with VSO Image Resizer
How to Reduce an Images Size with php
PHP BB Code - Links and Pics
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.