Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GD Library 1

Status
Not open for further replies.

audiopro

Programmer
Apr 1, 2004
3,165
GB
I have a mysterious problem with the useage of the following PHP call on a particular ISP.
I have used this and similar code many times on other websites without any issues at all.

What it does
Very simple, replace the words 'IMAGE_NAME' with the relative path and name of your image and the PHP script prints to screen, the image but reduced so that it's maximum dimension = 100.

The problem
I pick 12 picture names from a database and loop through them, calling the PHP code each time with the image name inserted into the imnam= variable. The 12 images attempt to print but only 7 of them do.

Getting them all to display
If I copy the code from one of the non-displayed pictures, put it into the address bar and return to the original page, all the images are now displayed.

I am looking for possible reasons why this is happeneing.
It may be worth mentioning that the code is being called using SSI via a Perl script although I have done the same thing on 100's of occasions, on other ISP's, without this issue.

The ISP are a waste of space when it comes to anything which helps a developer, they would rather just host people with 3 page static sites and hope they don't ask anything complicated.

Has anyone come across this issue before?

Code:
<img border='1' title='title' style='float:left;' src="sitename/script.php?imnam=IMAGE_NAME&amp;maxwid=100&amp;maxhi=100" alt=''>


Code:
<?php
	$img_name=$_GET['imnam'];

	$origsize=GetImageSize($img_name);
	$max_wid=$_GET['maxwid'];
	$max_ite=$_GET['maxhi'];

	$Fonts=$_GET['norat'];

	$src_img = ImageCreateFromJPEG($img_name);
	$width_ratio  = ($origsize[0] / $max_wid);
	$height_ratio = ($origsize[1] / $max_ite);
 
	if($width_ratio >=$height_ratio) 
	{
	   $ratio = $width_ratio;
	}
	else
	{
	   $ratio = $height_ratio;
	}
	$new_width    = ($origsize[0] / $ratio);
	$new_height   = ($origsize[1] / $ratio);
	$new_width = round($new_width);
	$new_height= round($new_height);
	$thumb = ImageCreateTrueColor($new_width,$new_height);
	$grey = imagecolorallocate($thumb, 201, 201, 201);
	$white = imagecolorallocate($thumb, 255, 255, 255);
	$offse=4;
	ImageCopyResampled($thumb, $src_img, 0,0,0,0,($new_width),($new_height),$origsize[0],$origsize[1]);
	$im = imagecreatefrompng('owlmark.png');
	imagecopymerge ($thumb , $im , 0 , 0 , 0 , 0 , 250 , 250 , 20 );
	ImageJPEG($thumb);
	ImageDestroy($thumb);
?>

Keith
 
can you show the code for substituting the image name please.

 
I saved the source code of the created page to a new SHTML file to elliminate the calling routine out of the equation. The 12 calls to the PHP script take the following form.
Code:
<img border='1' title='title' style='float:left;' src="sitename/script.php?imnam=prodims/010171.jpg&maxwid=100&maxhi=100" alt=''>

Keith
 
i'd guess that's the problem then. you need to urlencode your query string elements.
if you show us the code that _creates_ the links, we can doubtless help if you need.
 
I am not sure I follow your logic there.
The .shtml page with all the completed links in it still doesn't work.
The code that creates the links is no longer involved, it is now a simple static page.

The ISP are blaming too many instances of PHP running at the same time, yet the same script is opened and closed for each image. To prove a point, I increased the number of images from 12 to 1000 and all are loaded after the refresh method mentioned earlier.
The error logs do mention the odd 'Premature end of script headers' but only a small number.

Keith
 
try this link instead

<img border='1' title='title' style='float:left;' src="sitename/script.php?imnam=prodims%2F010171.jpg&maxwid=100&maxhi=100" alt='' />

 
I will try as you suggest but I think the issue may be the number of concurrent instances of PHP. The ISP limit this to 5 and I feel that a service which is advertised as business plus is pretty darned poor if I can only load 5 images per product list page.
I could solve this problem by creating a set of pictures resized to the required dimensions but why should I do that so that the ISP can carry on offering an inferior service.

Is it me or does the internet get worse as time goes on?

Keith
 
possibly, that is so but assumedly you cache the converted images and the php script is used to redirect to the cached image rather than resample for every request? If so, the duration of each php thread will be minimal.

and you'd be getting odd errors one assumes. what does your php error log and apache error log report?

 
I didn't realise it was possible to cache individual images, I thought that was only possible with pages.
The problem with this site is each time it is loaded it displays a selection of random images. The available images change at least daily and at busy times hourly as they are uploaded by customers and manually checked before being included. Once the item is sold, the image is removed automatically.

Keith
 
i will write you some cacheing and redirect code and post back. it might take an hour as I have another task in hand.
 
i've not tested this at all. just typed it straight into the editor.

you must change the way that you create the image tags for this file to work. also set the parameters at the start of the class carefully.

Code:
[COLOR=#990000]<?php[/color]
[i][COLOR=#9A1900]/*[/color][/i]
[i][COLOR=#9A1900] * when you are serving your image tag do this[/color][/i]
[i][COLOR=#9A1900] * echo getImageTag(20101, 200, 200);  to output a tag for the imageID 20101 with a maxheight and width of 200 px[/color][/i]
[i][COLOR=#9A1900] */[/color][/i]


[i][COLOR=#9A1900]//deal with old calls[/color][/i]
[b][COLOR=#0000FF]if[/color][/b][COLOR=#990000]([/color][b][COLOR=#000000]basename[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$_SERVER[/color][COLOR=#990000][[/color][COLOR=#FF0000]'REQUEST_URI'[/color][COLOR=#990000]])[/color] [COLOR=#990000]==[/color] [b][COLOR=#0000FF]__FILE__[/color][/b] [COLOR=#990000])[/color][COLOR=#FF0000]{[/color]
[tab][COLOR=#009900]$imageID[/color] [COLOR=#990000]=[/color] [COLOR=#009900]$_GET[/color][COLOR=#990000][[/color][COLOR=#FF0000]'imnam'[/color][COLOR=#990000]];[/color]
[tab][COLOR=#009900]$bits[/color] [COLOR=#990000]=[/color] [b][COLOR=#000000]explode[/color][/b][COLOR=#990000]([/color][COLOR=#FF0000]'/'[/color][COLOR=#990000],[/color] [COLOR=#009900]$imageID[/color][COLOR=#990000]);[/color]
[tab][COLOR=#009900]$imageID[/color] [COLOR=#990000]=[/color] [b][COLOR=#000000]end[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$imageID[/color][COLOR=#990000]);[/color]
[tab][COLOR=#009900]$imageID[/color] [COLOR=#990000]=[/color] [b][COLOR=#000000]explode[/color][/b][COLOR=#990000]([/color][COLOR=#FF0000]'.'[/color][COLOR=#990000],[/color] [COLOR=#009900]$imageID[/color][COLOR=#990000]);[/color]
[tab][COLOR=#009900]$imageID[/color] [COLOR=#990000]=[/color] [COLOR=#009900]$imageID[/color][COLOR=#990000][[/color][COLOR=#993399]0[/color][COLOR=#990000]];[/color]
[tab][COLOR=#009900]$i[/color] [COLOR=#990000]=[/color] [b][COLOR=#0000FF]new[/color][/b] [b][COLOR=#000000]image[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$imageID[/color][COLOR=#990000]);[/color]
[tab][COLOR=#009900]$i[/color][COLOR=#990000]->[/color][b][COLOR=#000000]serve[/color][/b][COLOR=#990000]();[/color]
[COLOR=#FF0000]}[/color]


[b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]getImageTag[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$imageID[/color][COLOR=#990000],[/color] [COLOR=#009900]$maxHeight[/color][COLOR=#990000],[/color] [COLOR=#009900]$maxWidth[/color][COLOR=#990000])[/color][COLOR=#FF0000]{[/color]
[tab][COLOR=#009900]$i[/color] [COLOR=#990000]=[/color] [b][COLOR=#0000FF]new[/color][/b] [b][COLOR=#000000]image[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$imageID[/color][COLOR=#990000]);[/color]
[tab][b][COLOR=#0000FF]return[/color][/b] [COLOR=#009900]$i[/color][COLOR=#990000]->[/color][b][COLOR=#000000]getImgTag[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$maxHeight[/color][COLOR=#990000],[/color] [COLOR=#009900]$maxWidth[/color][COLOR=#990000]);[/color]
[COLOR=#FF0000]}[/color]

[b][COLOR=#0000FF]class[/color][/b] image[COLOR=#FF0000]{[/color]
[tab]
[tab][i][COLOR=#9A1900]//change this to the relative path from this file to the image cache directory.[/color][/i]
[tab]
[tab]private [COLOR=#009900]$cacheDir[/color] [COLOR=#990000]=[/color] [COLOR=#FF0000]'imageCacheDir/'[/color][COLOR=#990000];[/color] [i][COLOR=#9A1900]//don't forget trailing slash[/color][/i]
[tab]
[tab][i][COLOR=#9A1900]//change this to the relative path from this file to the image directory. don't forget the trailing slash[/color][/i]
[tab]private [COLOR=#009900]$imageDir[/color] [COLOR=#990000]=[/color] [COLOR=#FF0000]'images/'[/color][COLOR=#990000];[/color]
[tab]
[tab][i][COLOR=#9A1900]//change this to the web accessible path to the image cache directory.  don't forget the trailing slash.[/color][/i]
[tab]private [COLOR=#009900]$cacheRoot[/color] [COLOR=#990000]=[/color] [COLOR=#FF0000]'[URL unfurl="true"]http://somedomain.com/imagecachedir/'[/URL][/color][COLOR=#990000];[/color]
[tab]
[tab][i][COLOR=#9A1900]//this determines how quickly unused cache files are deleted[/color][/i]
[tab]private [COLOR=#009900]$gc[/color] [COLOR=#990000]=[/color] [COLOR=#993399]2592000[/color][COLOR=#990000];[/color] [i][COLOR=#9A1900]//30 days;[/color][/i]
[tab]
[tab][i][COLOR=#9A1900]//change this to point to absolute url of the owlmark[/color][/i]
[tab]private [COLOR=#009900]$owlmark[/color] [COLOR=#990000]=[/color] [COLOR=#FF0000]'owlmark.png'[/color][COLOR=#990000];[/color]
[tab]
[tab]public [b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]__construct[/color][/b][COLOR=#990000]([/color] [COLOR=#009900]$imageID[/color] [COLOR=#990000]=[/color] NULL[COLOR=#990000])[/color][COLOR=#FF0000]{[/color]
[tab][tab][COLOR=#009900]$this[/color][COLOR=#990000]->[/color]imageID [COLOR=#990000]=[/color] [COLOR=#009900]$imageID[/color][COLOR=#990000];[/color]
[tab][COLOR=#FF0000]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]getImgTag[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$maxHeight[/color][COLOR=#990000],[/color] [COLOR=#009900]$maxWidth[/color][COLOR=#990000])[/color][COLOR=#FF0000]{[/color]
[tab][tab][COLOR=#009900]$file[/color] [COLOR=#990000]=[/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color][b][COLOR=#000000]isCached[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$maxHeight[/color][COLOR=#990000],[/color] [COLOR=#009900]$maxWidth[/color][COLOR=#990000]);[/color]
[tab][tab][b][COLOR=#0000FF]if[/color][/b] [COLOR=#990000](![/color][COLOR=#009900]$file[/color][COLOR=#990000]):[/color]
[tab][tab][tab][COLOR=#009900]$file[/color] [COLOR=#990000]=[/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color][b][COLOR=#000000]cache[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$maxHeight[/color][COLOR=#990000],[/color] [COLOR=#009900]$maxWidth[/color][COLOR=#990000]);[/color]
[tab][tab][tab][b][COLOR=#0000FF]if[/color][/b][COLOR=#990000](![/color][COLOR=#009900]$file[/color][COLOR=#990000])[/color] [b][COLOR=#0000FF]return[/color][/b] false[COLOR=#990000];[/color]
[tab][tab][b][COLOR=#0000FF]endif[/color][/b][COLOR=#990000];[/color]
[tab][tab][b][COLOR=#0000FF]return[/color][/b] [COLOR=#FF0000]"<img src=\"{$this->cacheRoot} . $file\"/>"[/color][COLOR=#990000];[/color]
[tab][COLOR=#FF0000]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]serve[/color][/b] [COLOR=#990000]()[/color][COLOR=#FF0000]{[/color]
[tab][tab][COLOR=#009900]$maxHeight[/color] [COLOR=#990000]=[/color] [b][COLOR=#0000FF]isset[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$_GET[/color][COLOR=#990000][[/color][COLOR=#FF0000]'maxhi'[/color][COLOR=#990000]])[/color] [COLOR=#990000]?[/color] [COLOR=#009900]$_GET[/color][COLOR=#990000][[/color][COLOR=#FF0000]'maxhi'[/color][COLOR=#990000]][/color] [COLOR=#990000]:[/color] false[COLOR=#990000];[/color]
[tab][tab][COLOR=#009900]$maxWidth[/color] [COLOR=#990000]=[/color][tab] [b][COLOR=#0000FF]isset[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$_GET[/color][COLOR=#990000][[/color][COLOR=#FF0000]'maxwid'[/color][COLOR=#990000]])[/color] [COLOR=#990000]?[/color] [COLOR=#009900]$_GET[/color][COLOR=#990000][[/color][COLOR=#FF0000]'maxwid'[/color][COLOR=#990000]][/color] [COLOR=#990000]:[/color] false[COLOR=#990000];[/color]
[tab][tab][b][COLOR=#0000FF]if[/color][/b] [COLOR=#990000]([/color]true [COLOR=#990000]==[/color] [COLOR=#990000]([/color][COLOR=#009900]$file[/color] [COLOR=#990000]=[/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color][b][COLOR=#000000]isCached[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$maxHeight[/color][COLOR=#990000],[/color] [COLOR=#009900]$maxWidth[/color][COLOR=#990000]))[/color] [COLOR=#990000]):[/color]
[tab][tab][tab][b][COLOR=#0000FF]if[/color][/b][COLOR=#990000](![/color][b][COLOR=#000000]headers_sent[/color][/b][COLOR=#990000]()):[/color]
[tab][tab][tab][tab][b][COLOR=#000000]header[/color][/b][COLOR=#990000]([/color][COLOR=#FF0000]"Location: "[/color] [COLOR=#990000].[/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color]cacheRoot [COLOR=#990000].[/color] [COLOR=#009900]$file[/color][COLOR=#990000]);[/color]
[tab][tab][tab][b][COLOR=#0000FF]endif[/color][/b][COLOR=#990000];[/color]
[tab][tab][tab][b][COLOR=#000000]touch[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$file[/color][COLOR=#990000]);[/color]
[tab][tab][b][COLOR=#0000FF]endif[/color][/b][COLOR=#990000];[/color]
[tab][COLOR=#FF0000]}[/color]
[tab]
[tab]private [b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]isCached[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$maxHeight[/color][COLOR=#990000],[/color] [COLOR=#009900]$maxWidth[/color][COLOR=#990000])[/color][COLOR=#FF0000]{[/color]
[tab][tab][b][COLOR=#0000FF]return[/color][/b] [b][COLOR=#000000]file_exists[/color][/b][COLOR=#990000]([/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color]cacheDir [COLOR=#990000].[/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color]imageID [COLOR=#990000].[/color] [COLOR=#FF0000]"_"[/color] [COLOR=#990000].[/color] [COLOR=#009900]$maxHeight[/color] [COLOR=#990000].[/color] [COLOR=#FF0000]"_"[/color] [COLOR=#990000].[/color] [COLOR=#009900]$maxWidth[/color] [COLOR=#990000].[/color] [COLOR=#FF0000]'.jpg'[/color][COLOR=#990000])[/color] [COLOR=#990000]?[/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color]cacheDir [COLOR=#990000].[/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color]imageID [COLOR=#990000].[/color] [COLOR=#FF0000]"_"[/color] [COLOR=#990000].[/color] [COLOR=#009900]$maxHeight[/color] [COLOR=#990000].[/color] [COLOR=#FF0000]"_"[/color] [COLOR=#990000].[/color] [COLOR=#009900]$maxWidth[/color] [COLOR=#990000].[/color][COLOR=#FF0000]'.jpg'[/color][COLOR=#990000]:[/color] false[COLOR=#990000];[/color]
[tab][COLOR=#FF0000]}[/color]
[tab]
[tab]private [b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]garbageCollect[/color][/b][COLOR=#990000]()[/color][COLOR=#FF0000]{[/color]
[tab][tab][b][COLOR=#000000]clearstatcache[/color][/b][COLOR=#990000]();[/color]
[tab][tab][COLOR=#009900]$dh[/color] [COLOR=#990000]=[/color] [b][COLOR=#000000]opendir[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$this[/color][COLOR=#990000]->[/color]cacheDir[COLOR=#990000]);[/color]
[tab][tab][COLOR=#009900]$t[/color] [COLOR=#990000]=[/color] [b][COLOR=#000000]time[/color][/b][COLOR=#990000]();[/color]
[tab][tab][b][COLOR=#0000FF]while[/color][/b] [COLOR=#990000]([/color]FALSE [COLOR=#990000]!==[/color] [COLOR=#990000]([/color][COLOR=#009900]$file[/color] [COLOR=#990000]=[/color] [b][COLOR=#000000]readdir[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$dh[/color][COLOR=#990000]))):[/color]
[tab][tab][tab][b][COLOR=#0000FF]if[/color][/b][COLOR=#990000]([/color][b][COLOR=#000000]substr[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$file[/color][COLOR=#990000],[/color] [COLOR=#993399]0[/color][COLOR=#990000],[/color] [COLOR=#993399]1[/color][COLOR=#990000])[/color] [COLOR=#990000]==[/color] [COLOR=#FF0000]'.'[/color][COLOR=#990000])[/color] [b][COLOR=#0000FF]continue[/color][/b][COLOR=#990000];[/color] [i][COLOR=#9A1900]//ignore directories[/color][/i]
[tab][tab][tab][b][COLOR=#0000FF]if[/color][/b][COLOR=#990000]([/color][b][COLOR=#000000]is_dir[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$this[/color][COLOR=#990000]->[/color]cacheDir [COLOR=#990000].[/color] [COLOR=#009900]$file[/color][COLOR=#990000]))[/color] [b][COLOR=#0000FF]continue[/color][/b][COLOR=#990000];[/color]
[tab][tab][tab][b][COLOR=#0000FF]if[/color][/b] [COLOR=#990000](![/color][b][COLOR=#000000]is_file[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$this[/color][COLOR=#990000]->[/color]cacheDir [COLOR=#990000].[/color] [COLOR=#009900]$file[/color][COLOR=#990000]))[/color] [b][COLOR=#0000FF]continue[/color][/b][COLOR=#990000];[/color]
[tab][tab][tab][b][COLOR=#0000FF]if[/color][/b][COLOR=#990000]([/color][b][COLOR=#000000]filetype[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$this[/color][COLOR=#990000]->[/color]cacheDir [COLOR=#990000].[/color] [COLOR=#009900]$file[/color][COLOR=#990000])[/color] [COLOR=#990000]!==[/color] [COLOR=#FF0000]'file'[/color][COLOR=#990000])[/color] [b][COLOR=#0000FF]continue[/color][/b][COLOR=#990000];[/color]
[tab][tab][tab][COLOR=#009900]$parts[/color] [COLOR=#990000]=[/color] [b][COLOR=#000000]pathinfo[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$this[/color][COLOR=#990000]->[/color]cacheDir[COLOR=#990000].[/color] [COLOR=#009900]$file[/color][COLOR=#990000]);[/color]
[tab][tab][tab][b][COLOR=#0000FF]if[/color][/b][COLOR=#990000](![/color][b][COLOR=#000000]in_array[/color][/b][COLOR=#990000]([/color][b][COLOR=#000000]strtolower[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$parts[/color][COLOR=#990000][[/color][COLOR=#FF0000]'extension'[/color][COLOR=#990000]],[/color] [b][COLOR=#0000FF]array[/color][/b][COLOR=#990000]([/color][COLOR=#FF0000]'jpg'[/color][COLOR=#990000],[/color][COLOR=#FF0000]'jpeg'[/color][COLOR=#990000],[/color][COLOR=#FF0000]'bmp'[/color][COLOR=#990000],[/color][COLOR=#FF0000]'png'[/color][COLOR=#990000],[/color][COLOR=#FF0000]'ico'[/color][COLOR=#990000]))))[/color] [b][COLOR=#0000FF]continue[/color][/b][COLOR=#990000];[/color]
[tab][tab][tab][b][COLOR=#0000FF]if[/color][/b][COLOR=#990000]([/color][b][COLOR=#000000]fileatime[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$this[/color][COLOR=#990000]->[/color]cacheDir [COLOR=#990000].[/color] [COLOR=#009900]$file[/color][COLOR=#990000])[/color] [COLOR=#990000]+[/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color]gc [COLOR=#990000]>[/color] [COLOR=#009900]$t[/color] [COLOR=#990000])[/color] [b][COLOR=#0000FF]continue[/color][/b][COLOR=#990000];[/color]
[tab][tab][tab][COLOR=#009900]@unlink[/color][COLOR=#990000]([/color][COLOR=#009900]$this[/color][COLOR=#990000]->[/color]cacheDir [COLOR=#990000].[/color] [COLOR=#009900]$file[/color][COLOR=#990000]);[/color]
[tab][tab][b][COLOR=#0000FF]endwhile[/color][/b][COLOR=#990000];[/color]
[tab][COLOR=#FF0000]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]__destruct[/color][/b][COLOR=#990000]()[/color][COLOR=#FF0000]{[/color]
[tab][tab][COLOR=#009900]$this[/color][COLOR=#990000]->[/color][b][COLOR=#000000]garbageCollect[/color][/b][COLOR=#990000]();[/color]
[tab][COLOR=#FF0000]}[/color]
[tab]
[tab]private [b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]cache[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$maxHeight[/color][COLOR=#990000],[/color] [COLOR=#009900]$maxWidth[/color][COLOR=#990000])[/color][COLOR=#FF0000]{[/color]
[tab][tab]
[tab][tab][COLOR=#009900]$original[/color] [COLOR=#990000]=[/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color][b][COLOR=#000000]getOriginal[/color][/b][COLOR=#990000]();[/color]
[tab][tab][b][COLOR=#0000FF]if[/color][/b][COLOR=#990000](![/color][COLOR=#009900]$original[/color][COLOR=#990000])[/color] [b][COLOR=#0000FF]return[/color][/b] false[COLOR=#990000];[/color]
[tab][tab]
[tab][tab][i][COLOR=#9A1900]/*[/color][/i]
[i][COLOR=#9A1900][tab][tab] * get scales[/color][/i]
[i][COLOR=#9A1900][tab][tab] */[/color][/i]
[tab][tab][b][COLOR=#0000FF]list[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$width[/color][COLOR=#990000],[/color] [COLOR=#009900]$height[/color][COLOR=#990000],[/color] [COLOR=#009900]$type[/color][COLOR=#990000],[/color] [COLOR=#009900]$attr[/color][COLOR=#990000])[/color] [COLOR=#990000]=[/color] [b][COLOR=#000000]getimagesize[/color][/b][COLOR=#990000]([/color] [COLOR=#009900]$original[/color] [COLOR=#990000]);[/color]
[tab][tab][b][COLOR=#0000FF]if[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$maxHeight[/color] [COLOR=#990000]==[/color] [COLOR=#993399]0[/color] [COLOR=#990000]||[/color] [COLOR=#009900]$maxWidth[/color] [COLOR=#990000]==[/color] [COLOR=#993399]0[/color][COLOR=#990000]):[/color]
[tab][tab][tab][COLOR=#009900]$height[/color] [COLOR=#990000]=[/color] [COLOR=#009900]$maxHeight[/color][COLOR=#990000];[/color]
[tab][tab][tab][COLOR=#009900]$width[/color] [COLOR=#990000]=[/color] [COLOR=#009900]$maxWidth[/color][COLOR=#990000];[/color]
[tab][tab][b][COLOR=#0000FF]else[/color][/b][COLOR=#990000]:[/color]
[tab][tab][tab][b][COLOR=#0000FF]if[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$height[/color] [COLOR=#990000]>[/color] [COLOR=#009900]$width[/color][COLOR=#990000]):[/color]
[tab][tab][tab][tab][COLOR=#009900]$newHeight[/color] [COLOR=#990000]=[/color] [COLOR=#009900]$maxHeight[/color] [COLOR=#990000]<[/color] [COLOR=#009900]$height[/color] [COLOR=#990000]?[/color] [b][COLOR=#000000]round[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$maxHeight[/color][COLOR=#990000])[/color] [COLOR=#990000]:[/color] [b][COLOR=#000000]round[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$height[/color][COLOR=#990000]);[/color]
[tab][tab][tab][tab][COLOR=#009900]$newWidth[/color] [COLOR=#990000]=[/color] [b][COLOR=#000000]round[/color][/b][COLOR=#990000]([/color] [COLOR=#009900]$width[/color] [COLOR=#990000]*[/color] [COLOR=#990000]([/color][COLOR=#009900]$newHeight[/color][COLOR=#990000]/[/color][COLOR=#009900]$height[/color][COLOR=#990000])[/color] [COLOR=#990000]);[/color]
[tab][tab][tab][b][COLOR=#0000FF]else[/color][/b][COLOR=#990000]:[/color]
[tab][tab][tab][tab][COLOR=#009900]$newWidth[/color] [COLOR=#990000]=[/color] [COLOR=#009900]$maxWidth[/color] [COLOR=#990000]<[/color] [COLOR=#009900]$width[/color] [COLOR=#990000]?[/color] [b][COLOR=#000000]round[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$maxWidth[/color][COLOR=#990000])[/color] [COLOR=#990000]:[/color] [b][COLOR=#000000]round[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$width[/color][COLOR=#990000]);[/color]
[tab][tab][tab][tab][COLOR=#009900]$newHeight[/color] [COLOR=#990000]=[/color] [b][COLOR=#000000]round[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$height[/color] [COLOR=#990000]*[/color] [COLOR=#990000]([/color][COLOR=#009900]$newWidth[/color][COLOR=#990000]/[/color][COLOR=#009900]$width[/color][COLOR=#990000]));[/color]
[tab][tab][tab][b][COLOR=#0000FF]endif[/color][/b][COLOR=#990000];[/color]
[tab][tab][b][COLOR=#0000FF]endif[/color][/b][COLOR=#990000];[/color]
[tab][tab]
[tab][tab][i][COLOR=#9A1900]/*[/color][/i]
[i][COLOR=#9A1900][tab][tab] * create source image;[/color][/i]
[i][COLOR=#9A1900][tab][tab] */[/color][/i]
[tab][tab][b][COLOR=#0000FF]switch[/color][/b] [COLOR=#990000]([/color][COLOR=#009900]$type[/color][COLOR=#990000]):[/color]
[tab][tab][tab][b][COLOR=#0000FF]case[/color][/b] IMAGETYPE_JPEG[COLOR=#990000]:[/color]
[tab][tab][tab][tab][COLOR=#009900]$src_img[/color] [COLOR=#990000]=[/color] [b][COLOR=#000000]imagecreatefromjpeg[/color][/b][COLOR=#990000]([/color] [COLOR=#009900]$original[/color] [COLOR=#990000]);[/color]
[tab][tab][tab][tab][b][COLOR=#0000FF]break[/color][/b][COLOR=#990000];[/color]
[tab][tab][tab][b][COLOR=#0000FF]case[/color][/b] IMAGETYPE_PNG[COLOR=#990000]:[/color]
[tab][tab][tab][tab][COLOR=#009900]$src_img[/color] [COLOR=#990000]=[/color] [b][COLOR=#000000]imagecreatefrompng[/color][/b][COLOR=#990000]([/color] [COLOR=#009900]$original[/color] [COLOR=#990000]);[/color]
[tab][tab][tab][tab][b][COLOR=#0000FF]break[/color][/b][COLOR=#990000];[/color]
[tab][tab][tab][b][COLOR=#0000FF]default[/color][/b][COLOR=#990000]:[/color]
[tab][tab][tab][tab][b][COLOR=#0000FF]die[/color][/b][COLOR=#990000];[/color]
[tab][tab][b][COLOR=#0000FF]endswitch[/color][/b][COLOR=#990000];[/color]
[tab]
[tab][tab][i][COLOR=#9A1900]/*[/color][/i]
[i][COLOR=#9A1900][tab][tab] * create resampled image[/color][/i]
[i][COLOR=#9A1900][tab][tab] */[/color][/i]
[tab][tab][COLOR=#009900]$thumb[/color] [COLOR=#990000]=[/color] [b][COLOR=#000000]imagecreatetruecolor[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$newWidth[/color][COLOR=#990000],[/color][COLOR=#009900]$newHeight[/color][COLOR=#990000]);[/color]
[tab][tab][COLOR=#009900]$grey[/color] [COLOR=#990000]=[/color] [b][COLOR=#000000]imagecolorallocate[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$thumb[/color][COLOR=#990000],[/color] [COLOR=#993399]201[/color][COLOR=#990000],[/color] [COLOR=#993399]201[/color][COLOR=#990000],[/color] [COLOR=#993399]201[/color][COLOR=#990000]);[/color]
[tab][tab][COLOR=#009900]$white[/color] [COLOR=#990000]=[/color] [b][COLOR=#000000]imagecolorallocate[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$thumb[/color][COLOR=#990000],[/color] [COLOR=#993399]255[/color][COLOR=#990000],[/color] [COLOR=#993399]255[/color][COLOR=#990000],[/color] [COLOR=#993399]255[/color][COLOR=#990000]);[/color]
[tab][tab][COLOR=#009900]$offse[/color][COLOR=#990000]=[/color][COLOR=#993399]4[/color][COLOR=#990000];[/color]
[tab][tab][b][COLOR=#000000]imagecopyresampled[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$thumb[/color][COLOR=#990000],[/color] [COLOR=#009900]$src_img[/color][COLOR=#990000],[/color] [COLOR=#993399]0[/color][COLOR=#990000],[/color][COLOR=#993399]0[/color][COLOR=#990000],[/color][COLOR=#993399]0[/color][COLOR=#990000],[/color][COLOR=#993399]0[/color][COLOR=#990000],([/color][COLOR=#009900]$newWidth[/color][COLOR=#990000]),([/color][COLOR=#009900]$newHeight[/color][COLOR=#990000]),[/color][COLOR=#009900]$width[/color][COLOR=#990000],[/color] [COLOR=#009900]$height[/color][COLOR=#990000]);[/color]
[tab][tab][COLOR=#009900]$im[/color] [COLOR=#990000]=[/color] [b][COLOR=#000000]imagecreatefrompng[/color][/b][COLOR=#990000]([/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color]owlMark [COLOR=#990000]);[/color]
[tab][tab][b][COLOR=#000000]imagecopymerge[/color][/b] [COLOR=#990000]([/color][COLOR=#009900]$thumb[/color] [COLOR=#990000],[/color] [COLOR=#009900]$im[/color] [COLOR=#990000],[/color] [COLOR=#993399]0[/color] [COLOR=#990000],[/color] [COLOR=#993399]0[/color] [COLOR=#990000],[/color] [COLOR=#993399]0[/color] [COLOR=#990000],[/color] [COLOR=#993399]0[/color] [COLOR=#990000],[/color] [COLOR=#993399]250[/color] [COLOR=#990000],[/color] [COLOR=#993399]250[/color] [COLOR=#990000],[/color] [COLOR=#993399]20[/color] [COLOR=#990000]);[/color]
[tab][tab]
[tab][tab][i][COLOR=#9A1900]/*[/color][/i]
[i][COLOR=#9A1900][tab][tab] * save image[/color][/i]
[i][COLOR=#9A1900][tab][tab] */[/color][/i]
[tab][tab][COLOR=#009900]$return[/color] [COLOR=#990000]=[/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color]cacheDir [COLOR=#990000].[/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color]imageID [COLOR=#990000].[/color] [COLOR=#FF0000]"_{$maxHeight}_{$maxWidth}.jpg"[/color][COLOR=#990000];[/color]
[tab][tab][b][COLOR=#000000]imagejpeg[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$thumb[/color][COLOR=#990000],[/color] [COLOR=#009900]$return[/color][COLOR=#990000]);[/color]
[tab][tab]
[tab][tab][i][COLOR=#9A1900]/*[/color][/i]
[i][COLOR=#9A1900][tab][tab] * clean up[/color][/i]
[i][COLOR=#9A1900][tab][tab] */[/color][/i]
[tab][tab][b][COLOR=#000000]imagedestroy[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$thumb[/color][COLOR=#990000]);[/color]
[tab][tab][b][COLOR=#000000]imagedestroy[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$im[/color][COLOR=#990000]);[/color]
[tab][tab][b][COLOR=#000000]imagedestroy[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$src_img[/color][COLOR=#990000]);[/color]
[tab][tab][b][COLOR=#0000FF]return[/color][/b] [COLOR=#009900]$return[/color][COLOR=#990000];[/color]
[tab][COLOR=#FF0000]}[/color]
[tab]
[tab]private [b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]getOriginal[/color][/b][COLOR=#990000]()[/color][COLOR=#FF0000]{[/color]
[tab][tab][COLOR=#009900]$matches[/color] [COLOR=#990000]=[/color] [b][COLOR=#000000]glob[/color][/b][COLOR=#990000]([/color][b][COLOR=#000000]realpath[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$this[/color][COLOR=#990000]->[/color]imageDir[COLOR=#990000])[/color] [COLOR=#990000].[/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color]imageID [COLOR=#990000].[/color] [COLOR=#FF0000]".*"[/color][COLOR=#990000]);[/color]
[tab][tab][i][COLOR=#9A1900]//just get the first one[/color][/i]
[tab][tab][b][COLOR=#0000FF]if[/color][/b] [COLOR=#990000]([/color][b][COLOR=#0000FF]isset[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$matches[/color][COLOR=#990000][[/color][COLOR=#993399]0[/color][COLOR=#990000]])[/color] [COLOR=#990000]&&[/color] [COLOR=#990000]![/color][b][COLOR=#0000FF]empty[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$matches[/color][COLOR=#990000][[/color][COLOR=#993399]0[/color][COLOR=#990000]])):[/color]
[tab][tab][tab][b][COLOR=#0000FF]return[/color][/b] [COLOR=#009900]$matches[/color][COLOR=#990000][[/color][COLOR=#993399]0[/color][COLOR=#990000]];[/color]
[tab][tab][b][COLOR=#0000FF]endif[/color][/b][COLOR=#990000];[/color]
[tab][tab][b][COLOR=#0000FF]return[/color][/b] false[COLOR=#990000];[/color]
[tab][COLOR=#FF0000]}[/color]
[COLOR=#FF0000]}[/color]
[COLOR=#990000]?>[/color]
 
Thanks for that, I will have a look into it later when I have a bit more time.

You know the scenario, nothing is urgent until they forgot to ask you to do something weeks ago, now it is due by Monday.

Keith
 
there's an error in the first bit. just spotted

Code:
[b][COLOR=#0000FF]if[/color][/b][COLOR=#990000]([/color][b][COLOR=#000000]basename[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$_SERVER[/color][COLOR=#990000][[/color][COLOR=#FF0000]'REQUEST_URI'[/color][COLOR=#990000]])[/color] [COLOR=#990000]==[/color] [b][COLOR=#0000FF]__FILE__[/color][/b] [COLOR=#990000])[/color][COLOR=#FF0000]{[/color]
[tab][COLOR=#009900]$bits[/color] [COLOR=#990000]=[/color] [b][COLOR=#000000]explode[/color][/b][COLOR=#990000]([/color][COLOR=#FF0000]'/'[/color][COLOR=#990000],[/color] [b][COLOR=#000000]trim[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$_GET[/color][COLOR=#990000][[/color][COLOR=#FF0000]'imnam'[/color][COLOR=#990000]]));[/color]
[tab][COLOR=#009900]$imageID[/color] [COLOR=#990000]=[/color] [b][COLOR=#000000]current[/color][/b][COLOR=#990000]([/color][b][COLOR=#000000]explode[/color][/b][COLOR=#990000]([/color][COLOR=#FF0000]'.'[/color][COLOR=#990000],[/color] [COLOR=#009900]$bits[/color][COLOR=#990000][[/color][b][COLOR=#000000]count[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$bits[/color][COLOR=#990000])[/color] [COLOR=#990000]-[/color] [COLOR=#993399]1[/color][COLOR=#990000]]));[/color]
[tab][COLOR=#009900]$i[/color] [COLOR=#990000]=[/color] [b][COLOR=#0000FF]new[/color][/b] [b][COLOR=#000000]image[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$imageID[/color][COLOR=#990000]);[/color]
[tab][COLOR=#009900]$i[/color][COLOR=#990000]->[/color][b][COLOR=#000000]serve[/color][/b][COLOR=#990000]();[/color]
[COLOR=#FF0000]}[/color]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top