Jump to content

Recommended Posts

I have a script that uploads my images to a folder and database which works fine. I am looking to display my images on the fly to resize them. How do I intergrate my image output string with the fly string.

 

Current output

echo '<img src="' . $dir . '/' . $image_id . '.jpg">';

 

Fly string

<img src="/scripts/thumb.php?src=/images/whatever.jpg&h=150&w=150&zc=1" alt="" />

 

Thanks for your help

Link to comment
https://forums.phpfreaks.com/topic/234902-on-the-fly-help-display-image/
Share on other sites

You can use PHP GD or PHP IMAGEMAJIC to process the image on the fly.

 

that said, I highly recommend automatically creating thumbs once images are uploaded and directly accessing them thumbs, as it will save server resources, becasue you wont be using all that image processing cpu cycles and ram on each request.

i agree with dealing with the resize on upload, i have a nifty cropper and resize that i did a good while back

<?php

function CropImage($NewWidth, $NewHeight, $source, $filetype, $dest)
{	
list($Width, $Height) = getimagesize($source);

switch($filetype)
{
	case 'gif':
	$SourceImage = imagecreatefromgif($source);
	break;

	case 'jpg':
	$SourceImage = imagecreatefromjpeg($source);
	break;

	case 'png':
	$SourceImage = imagecreatefrompng($source);
	break;
}

$NewImage = imagecreatetruecolor($NewWidth, $NewHeight);

$WidthRatio = $Width/$NewWidth;
$HeightRatio = $Height/$NewHeight;

$HalfNewHeight = $NewHeight/2;
$HalfNewWidth = $NewWidth/2;

if($Width > $Height)
{
	$AdjustedWidth = $Width / $HeightRatio;
	$HalfWidth = $AdjustedWidth / 2;
	$IntWidth = $HalfWidth - $HalfNewWidth;
	imagecopyresampled($NewImage, $SourceImage, -$IntWidth, 0, 0, 0, $AdjustedWidth, $NewHeight, $Width, $Height);
}
elseif(($Width < $Height) || ($Width == $Height))
{
	$AdjustedHeight = $Height / $WidthRatio;
	$HalfHeight = $AdjustedHeight / 2;
	$IntHeight = $HalfHeight - $HalfNewHeight;
	imagecopyresampled($NewImage, $SourceImage, 0, -$IntHeight, 0, 0, $NewWidth, $AdjustedHeight, $Width, $Height);
}
else
{
	imagecopyresampled($NewImage, $SourceImage, 0, 0, 0, 0, $NewWidth, $NewHeight, $Width, $Height);
}
imagejpeg($NewImage, $dest, 100);
}

?>

feel free to use and abuse. :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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