|
 |

| View previous topic :: View next topic |
| Author |
Message |
Wil Guest
|
Posted: Fri Mar 28, 2008 1:48 pm Post subject: Scaled Image Instances |
|
|
I may be missing something obvious, but when trying to automatically scale image and image into 3 versions (small, medium & large) I'm having trouble.
The applet seems to do something extra, then upload no problem but there is only 1 version of each image and that version doesn't open.
Without the instances it works a charm. Here's the applet code anyway:
| Code: | <applet name="jumpLoaderApplet"
code="jmaster.jumploader.app.JumpLoaderApplet.class"
archive="jumploader_z.jar"
width="800"
height="600"
mayscript>
<param name="uc_uploadUrl" value="upload-handler.php"/>
<param name="uc_uploadScaledImages" value="true"/>
<param name="uc_scaledInstanceNames" value="small,medium,large"/>
<param name="uc_scaledInstanceDimensions" value="100x100,300x300,1000x1000"/>
<param name="uc_scaledInstanceQualityFactors" value="700,700,700"/>
</applet> |
Here's the applet console output:
| Code: | ----------------------------------------------------
28.03.2008 13:43:04 - DEBUG - uploader status change: uploader, status:1
28.03.2008 13:43:04 - DEBUG - startThread() of uploadThread uploadThread_0, current file: null
28.03.2008 13:43:04 - DEBUG - file status change: Upload File [status:0, path:C:\Users\Public\Pictures\Sample Pictures\Autumn Leaves.jpg]
28.03.2008 13:43:04 - DEBUG - uploadThread uploadThread_0, current file: Upload File [status:1, path:C:\Users\Public\Pictures\Sample Pictures\Autumn Leaves.jpg] uploading Upload File [status:1, path:C:\Users\Public\Pictures\Sample Pictures\Autumn Leaves.jpg]
28.03.2008 13:43:04 - DEBUG - Preparing ZIP for Upload File [status:1, path:C:\Users\Public\Pictures\Sample Pictures\Autumn Leaves.jpg], path=C:\Users\WIL~1.LIN\AppData\Local\Temp\tmp_61646.zip
28.03.2008 13:43:04 - DEBUG - Preparing scaled instance for Upload File [status:1, path:C:\Users\Public\Pictures\Sample Pictures\Autumn Leaves.jpg], instanceName=small, dimension=100x100, qualityFactor=700
28.03.2008 13:43:04 - DEBUG - Preparing scaled instance for Upload File [status:1, path:C:\Users\Public\Pictures\Sample Pictures\Autumn Leaves.jpg], instanceName=medium, dimension=300x300, qualityFactor=700
28.03.2008 13:43:05 - DEBUG - Detected 'application/zip' content type for Upload File [status:1, path:C:\Users\WIL~1.LIN\AppData\Local\Temp\tmp_61646.zip]
28.03.2008 13:43:05 - DEBUG - [---------------- New request ----------------]
28.03.2008 13:43:05 - DEBUG - targetURL=http://client.junomedia.co.uk/java%2Dupload/upload-handler.php
28.03.2008 13:43:05 - DEBUG - Request head:
POST /java%2Dupload/upload-handler.php HTTP/1.0
Host: client.junomedia.co.uk
Content-Length: 24356
Content-Type: multipart/form-data; boundary=----------RKAJ3NkDssPYHAm4arquSw
28.03.2008 13:43:05 - DEBUG - Request formData:
------------RKAJ3NkDssPYHAm4arquSw
Content-Disposition: form-data; name="partitionIndex"
0
------------RKAJ3NkDssPYHAm4arquSw
Content-Disposition: form-data; name="fileId"
30637883
------------RKAJ3NkDssPYHAm4arquSw
Content-Disposition: form-data; name="lastModified"
2006-11-02T12:37:18.985+0000
------------RKAJ3NkDssPYHAm4arquSw
Content-Disposition: form-data; name="fileLength"
23668
------------RKAJ3NkDssPYHAm4arquSw
Content-Disposition: form-data; name="partitionCount"
1
28.03.2008 13:43:05 - DEBUG - Request filePart[0] :
------------RKAJ3NkDssPYHAm4arquSw
Content-Disposition: form-data; name="file"; filename="Autumn Leaves.jpg"
Content-Type: application/zip
28.03.2008 13:43:05 - DEBUG - Response content for Upload File [status:1, path:C:\Users\WIL~1.LIN\AppData\Local\Temp\tmp_61646.zip]
28.03.2008 13:43:05 - DEBUG - Moving file C:\WINDOWS\Temp\phpB98.tmp > Autumn Leaves.jpg: success<html>
<body>
<h1>GET content</h1>
<pre>Array
(
)
</pre>
<h1>POST content</h1>
<pre>Array
(
[partitionIndex] => 0
[fileId] => 30637883
[lastModified] => 2006-11-02T12:37:18.985+0000
[fileLength] => 23668
[partitionCount] => 1
)
</pre>
<h1>FILES content</h1>
<pre>Array
(
[file] => Array
(
[name] => Autumn Leaves.jpg
[type] => application/zip
[tmp_name] => C:\WINDOWS\Temp\phpB98.tmp
[error] => 0
[size] => 23668
)
)
</pre>
</body>
28.03.2008 13:43:05 - DEBUG - uploadThread uploadThread_0, current file: Upload File [status:1, path:C:\Users\WIL~1.LIN\AppData\Local\Temp\tmp_61646.zip] finished upload of Upload File [status:1, path:C:\Users\WIL~1.LIN\AppData\Local\Temp\tmp_61646.zip]
28.03.2008 13:43:05 - DEBUG - file status change: Upload File [status:1, path:C:\Users\WIL~1.LIN\AppData\Local\Temp\tmp_61646.zip]
28.03.2008 13:43:05 - DEBUG - uploader status change: uploader, status:0
|
Finally, the url of the test applet: http://client.junomedia.co.uk/java-upload/ Help please? |
|
| Back to top |
|
 |
Wil Guest
|
Posted: Fri Mar 28, 2008 2:03 pm Post subject: Zipped Image Instances |
|
|
After changing the extension of the uploaded file from jpg to zip I could see the uploaded had created the instances and zipped them up - so that's working fine.
The question is then, how do I get the uploader not to zip them and just upload each instance?
It might be worth mentioning now that I need the applet to resize them no matter if the resize instance is larger than the original. It would be great if it could do it to a maximum x / y value. Say if I want the image to be no larger than 300px wide OR 300px high, so a 400x250 would be resized to 300x188 and vice versa. |
|
| Back to top |
|
 |
jmaster Site Admin
Joined: 01 Jan 1970 Posts: 1156
|
Posted: Fri Mar 28, 2008 2:08 pm Post subject: |
|
|
Can hardly imagine what could be wrong - although actual web page is slightly modified than provided in this post, all seems to be processed correctly.
I would recommend to narrow problem - this could be problem on client (image processing, creating zip) or on server (file retrieval). Please check that temporary zip file (you can read it's path from console: C:\Users\WIL~1.LIN\AppData\Local\Temp\tmp_61646.zip) - is it OK? |
|
| Back to top |
|
 |
Wil Guest
|
Posted: Fri Mar 28, 2008 2:13 pm Post subject: |
|
|
| Yea, it's all fine it looks like that's the file that's been uploaded but renamed as a jpg. |
|
| Back to top |
|
 |
jmaster Site Admin
Joined: 01 Jan 1970 Posts: 1156
|
Posted: Fri Mar 28, 2008 2:16 pm Post subject: |
|
|
It is not possible to upload scaled images one by one - only in zip.
You can stretch images using <param name="uc_stretchImages" value="true"/>. Dimension specify bounding box, not target image dimension. All scaled images aspect ratio preserved. So, if you want, let's say, make all scaled images 300px wide (regardless its height), just specify really big value for height, i.e. 300x10000. |
|
| Back to top |
|
 |
Wil Guest
|
Posted: Fri Mar 28, 2008 2:33 pm Post subject: |
|
|
So to retrieve the scaled images I would need to extract the zip file? I can see from the php that it's detected the right content type, but somehow mapped the wrong extension, I can catch that.
Just to double check, when uploading scaled images it will only zip and upload them as one file? |
|
| Back to top |
|
 |
Wil Guest
|
Posted: Fri Mar 28, 2008 3:26 pm Post subject: Unzipping Scaled Image Instances |
|
|
I've quickly altered the PHP script you gave as an example to unzip and prefix the uploaded images as instances. It unzips and copies each entry in the zip and renames them according to their original name and instance name.
For example, uploading an image called 'my-image.jpg' with two instance names of 'small' and 'large' would produce two unzipped images in the orignal upload folder called 'my-image_small.jpg' and my-image_large.jpg'.
I thought it might come in useful so here it is:
| Code: | <?php
//----------------------------------------------
// upload file handler script
//----------------------------------------------
//
// specify file parameter name
$file_param_name = 'file';
//
// retrieve uploaded file name
$file_name = $_FILES[ $file_param_name ][ 'name' ];
//
// retrieve uploaded file path (temporary stored by php engine)
$source_file_path = $_FILES[ $file_param_name ][ 'tmp_name' ];
//
// construct target file path (desired location of uploaded file) -
// here we put to the web server document root (i.e. '/home/wwwroot')
// using user supplied file name
$target_file_path = $file_name;
$target_file_path = rtrim($target_file_path,'jpg');
$target_file_path = $target_file_path.'zip';
//
// move uploaded file
echo "Moving file " . $source_file_path . " > " . $target_file_path . ": ";
if( move_uploaded_file( $source_file_path, $target_file_path ) ) {
echo "success";
} else{
echo "failure";
}
// set a temporary location for unzipped files
$unzipDir = 'unzipped';
// remove the file extension from the filename (for prefixing)
$file_name = substr($file_name,0,-4);
// find the current directory (absolute server val)
$currentDir = dirname(__FILE__);
// create the zip object
$zip = new ZipArchive;
if ($zip->open($target_file_path) === TRUE) {
// extract the individual items to the temp folder
$zip->extractTo($unzipDir.'/');
$zip->close();
// open the temp folder
$handle = opendir($unzipDir);
// loop every file that isn't a shortcut
while (FALSE !== ($file = readdir($handle))) {
if ('.' !== $file && '..' !== $file) {
// source file is in the unzipped dir
$source = $currentDir.'\\'.$unzipDir.'\\'.$file;
// target file is prefixed with the original filename and moved up one
// NOTE *nix users might need to fiddle with back slashes here.
$target = $currentDir.'\\'.$file_name.'_'.$file;
rename ($source,$target);
unlink ($target_file_path);
}
}
closedir($handle);
}
//
// below is trace of variables
?>
<html>
<body>
<h1>GET content</h1>
<pre><?print_r( $_GET );?></pre>
<h1>POST content</h1>
<pre><?print_r( $_POST );?></pre>
<h1>FILES content</h1>
<pre><?print_r( $_FILES );?></pre>
</body>
|
|
|
| Back to top |
|
 |
jmaster Site Admin
Joined: 01 Jan 1970 Posts: 1156
|
Posted: Fri Mar 28, 2008 4:08 pm Post subject: |
|
|
| thank you. |
|
| Back to top |
|
 |
robfaas
Joined: 24 Apr 2008 Posts: 15
|
Posted: Fri Apr 25, 2008 6:41 am Post subject: |
|
|
Great php! This was exactly what I needed. This is a good help if you want to create an album with thumbnails.
One detail: I noticed that the temp files in the unzipped directory weren't deleted.
I adjusted the lines below:
rename ($source,$target);
unlink ($target_file_path);
}
}
closedir($handle);
into:
rename ($source,$target);
unlink ($source); // deletes the temp file in the unzipped dir
}
}
unlink ($target_file_path); // deletes the .zip file
closedir($handle); |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|
 |
|