Jump to content

Re-making thumbnails?


Guest

Recommended Posts

In v2, if you had to restore images, you could open each product in the store and it would regenerate thumbnails. V3 doesn't seem to be doing this so after an upgrade, moving the images to the new directory leaves all the thumbs saying "no image available" even though the large image displays when you click on the thumb.

So my question for all you script gurus out there, is can you come up with a script we can run to re-create the thumbs??? I'm thinking the upload.php script could be modified to do this, but my php scripting skills aren't quite up to the challenge.

The script I'm talking about is in admin/filemanager/upload.php and is below. It includes a section on generating the thumbs it looks like.

<?php

/*

 * FCKeditor - The text editor for internet

 * Copyright (C) 2003-2004 Frederico Caldeira Knabben

 *

 * Licensed under the terms of the GNU Lesser General Public License

 * (http://www.opensource.org/licenses/lgpl-license.php)

 *

 * For further information go to http://www.fredck.com/admin/includes/rte/ 

 * or contact [email protected].

 *

 * upload.php: Basic file upload manager for the editor. You have

 *   to have set a directory called "userimages" in the root folder

 *   of your web site.

 *

 * Authors:

 *   Frederic TYNDIUK (http://www.ftls.org/ - tyndiuk[at]ftls.org)

 * Modded by:

 *	Alistair Brookbanks Devellion Limited

 */



// Init var :

include("../../includes/global.inc.php");

require_once("../../classes/db.inc.php");

$db = new db();

include_once("../../includes/functions.inc.php");

$config = fetchDbConfig("config");

include_once("../../language/".$config['defaultLang']."/lang.inc.php");

$enableSSl = 1;

include_once("../../includes/sslSwitch.inc.php");

include("../../classes/gd.inc.php");



// End int var



?>



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >

<HTML>

	<HEAD>

  <TITLE><?php echo $lang['admin']['filemanager']['file_uploader']; ?></TITLE>

  <LINK rel="stylesheet" type="text/css" href="../includes/rte/css/fck_dialog.css">

  <LINK rel="stylesheet" type="text/css" href="../styles/style.css">

	</HEAD>

	<BODY>

	<p class="pageTitle"><?php echo $lang['admin']['filemanager']['upload_image']; ?></p>

	<?php if($_GET["custom"]==1){ ?>

	

	<form action="<?php echo $GLOBALS['rootRel'];?>admin/filemanager/upload.php" method="post" enctype="multipart/form-data" target="_self">

	<table align="center" border="0" cellpadding="3" cellspacing="0" class="mainTable">

    <tr>

    <td class="tdTitle"><?php echo $lang['admin']['filemanager']['please_browse_img']; ?></td>

  </tr>

  <tr>

    <td><input name="FCKeditor_File" type="file" class="textbox"></td>

  </tr>

  <tr>

    <td align="center"><input name="submit" type="submit" class="submit" value="<?php echo $lang['admin']['filemanager']['upload_image']; ?>"></td>

  </tr>

</table>

	<?php if(isset($_GET['redir'])){ ?>

	<input type="hidden" value="0" name="redir">

	<?php } ?>

	<input type="hidden" value="1" name="custom">

	</form>

	<?php } else { ?>

	<form>

  <TABLE>

  	<TR>

    <TD>



<span class="copyText">

<?php 

if($HTTP_POST_FILES['FCKeditor_File']['size'] > $config['maxImageUploadSize']) { 



	echo sprintf($lang['admin']['filemanager']['file_too_big'],$HTTP_POST_FILES['FCKeditor_File']['name'],format_size($config['maxImageUploadSize'])); 

	unlink($HTTP_POST_FILES['FCKeditor_File']['tmp_name']);



} elseif (file_exists($GLOBALS['rootDir']."/images/uploads/".$HTTP_POST_FILES['FCKeditor_File']['name'])) {



	echo sprintf($lang['admin']['filemanager']['img_already_exists'],$HTTP_POST_FILES['FCKeditor_File']['name']);



} elseif (!is_uploaded_file($HTTP_POST_FILES['FCKeditor_File']['tmp_name'])) { 



	echo $lang['admin']['filemanager']['upload_too_large'];



} elseif ($HTTP_POST_FILES['FCKeditor_File']['type'] != "image/jpeg" AND $HTTP_POST_FILES['FCKeditor_File']['type'] != "image/png"  AND $HTTP_POST_FILES['FCKeditor_File']['type'] != "image/x-png" AND $HTTP_POST_FILES['FCKeditor_File']['type'] != "image/jpg" AND $HTTP_POST_FILES['FCKeditor_File']['type'] != "image/x-jpeg" AND $HTTP_POST_FILES['FCKeditor_File']['type'] != "image/gif"){



	echo sprintf($lang['admin']['filemanager']['not_valid_mime'],$HTTP_POST_FILES['FCKeditor_File']['name']);

	unlink($HTTP_POST_FILES['FCKeditor_File']['tmp_name']); 



} else {

	

	if (is_uploaded_file($HTTP_POST_FILES['FCKeditor_File']['tmp_name'])) {

  $savefile = $GLOBALS['rootDir']."/images/uploads/".$HTTP_POST_FILES['FCKeditor_File']['name'];



	if (move_uploaded_file($HTTP_POST_FILES['FCKeditor_File']['tmp_name'], $savefile)) {

  @chmod($savefile, 0644);

  

  // if image is a JPG check thumbnail doesn't exist and if not make one

	$imageFormat = strtoupper(ereg_replace(".*\.(.*)$","\\1",$HTTP_POST_FILES['FCKeditor_File']['name']));

	

	if($imageFormat == "JPG" || $imageFormat == "JPEG" || $imageFormat == "PNG" || ($imageFormat == "GIF" && $config['gdGifSupport']==1)){

  

  

  // check image is not too big

  $size = getimagesize($savefile);

  

  if(($size[0] > $config['gdmaxImgSize']) OR ($size[1] > $config['gdmaxImgSize'])){

  

  @chmod($savefile, 0775);

  

  $thumb=new thumbnail($savefile);

  $thumb->size_auto($config['gdmaxImgSize']);

  $thumb->jpeg_quality($config['gdquality']);

  $thumb->save($savefile);

  

  }

  

  

  if(file_exists($GLOBALS['rootDir']."/images/uploads/thumbs/thumb_".$HTTP_POST_FILES['FCKeditor_File']['name'])){

  	@chmod($GLOBALS['rootDir']."/images/uploads/thumbs/thumb_".$HTTP_POST_FILES['FCKeditor_File']['name'], 0775);

  	unlink($GLOBALS['rootDir']."/images/uploads/thumbs/thumb_".$HTTP_POST_FILES['FCKeditor_File']['name']);

  }

  

  $thumb=new thumbnail($GLOBALS['rootDir']."/images/uploads/".$HTTP_POST_FILES['FCKeditor_File']['name']);

  // see if we need to resize 

  if(($size[0] > $config['gdthumbSize']) OR ($size[1] > $config['gdthumbSize'])){

  	$thumb->size_auto($config['gdthumbSize']);

  } else {

  	$thumb->size_auto($size[0]);

  }

  $thumb->jpeg_quality($config['gdquality']);

  $thumb->save($GLOBALS['rootDir']."/images/uploads/thumbs/thumb_".$HTTP_POST_FILES['FCKeditor_File']['name']);

	}

  

  

  echo sprintf($lang['admin']['filemanager']['image_upload_success'],$HTTP_POST_FILES['FCKeditor_File']['name']);

  	

  	if(!isset($_POST['redir'])){

?>

  <script language=javascript>

  <?php if($_POST["custom"]==1){ ?>

  window.opener.addImage('<?php echo $HTTP_POST_FILES['FCKeditor_File']['name']; ?>', '<?php echo $GLOBALS['rootRel']."images/uploads/".$HTTP_POST_FILES['FCKeditor_File']['name']; ?>');

  <?php } else { ?>

  window.opener.setImage('<?php echo $GLOBALS['rootRel']."images/uploads/".$HTTP_POST_FILES['FCKeditor_File']['name']; ?>');

  <?php } ?>

  window.close();

  </SCRIPT>

  <?php

  	} // end if not set redir

  

  }

	}



	

} ?></span>

    </TD>

  	</TR>

  </TABLE>

	</form>

	<?php }  ?>

	<p align="center"><?php if(isset($_POST['submit'])){ ?><INPUT type="button" class="submit" value="<?php echo $lang['admin']['filemanager']['back']; ?>" onclick="history.back()"><?php } ?> 

	<INPUT type="button" class="submit" value="<?php echo $lang['admin']['filemanager']['close_window']; ?>"  onclick="<?php if(isset($_POST['redir'])) { echo "window.opener.location.reload();"; } ?> javascript:window.close();"></p>

	</BODY>

</HTML>

Link to comment
Share on other sites

Guest jeromas

You can use the script I wrote here:

http://www.cubecart.com/site/forums/index....showtopic=10278

Basically, you put images you want to have thumbnailed into a directory along with the script, call the script via your web browser, and there you go, you have thumbnails for any jpeg, png, or gifs that were in the folder. The script will ignore any other files/folders in the directory, and you can change the variables at the beginning of the script to set your thumbnail size along with a couple of other things.

Link to comment
Share on other sites

Any idea why I get an "Internal Server Error" when I try to run your thumbnail_creator script????

My friend's store has over 5000 images in the directory and somehow the thumbnails were lost. I checked the chmod and both images and uploads are set to 777 and I'm trying to run it in uploads where all the images are. But I get ...

"Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request."

It also mentions to check the error log but there is nothing in the log about this (last thing it logged was 8/15 in fact).

I really need to run this script :) Ideas?

Link to comment
Share on other sites

I don't know if you are using a shared IP address, but one of the issues I had before I bought a dedicated IP address was that I could not successfully use commands like fopen(), fwrite(), etc, as my webhost would not allow it. I think the main reason for them not letting me use commands like that was because fopen() can be used to open URLs, which in turn could lead to writing a web-spider, which most webhosts don't like being run on their boxes due to performance hits on the servers. It may be the same issue for commands like opendir() and readdir() that are used in the script, and that could be some of the reason you are seeing the issues in the script with the 500 internal server error, or you may be trying to run a script in a directory where it is not permitted to do so.

500 internal server errors suck, because they are so cryptic, and not getting anything in the error log doesn't help. Please let me know if you figure it out.

Link to comment
Share on other sites

It is a shared IP so guess that won't work */* Might have to move all the images to one of my other domains with its own ip and try running it then transferring all the images back. Hmmmmm. I'll give it a try when I get a chance.

And agree on the cryptic messages - most server error messages are so dang cryptic I never know what to try doing :)

Link to comment
Share on other sites

One other suggestion is to install the Apache webserver on your local computer and run the script from there. If you are using windows, Apache is a very easy install, and should be pretty much be pre-configured to run 'out of the box' (it's open source though). All you would need to do after that is drop the script inside your document root, navigate to http://localhost/thumbnail_creator.php (along with all of your images), and you'd be set.

Good luck -- please let me know if the script will not work for you.

Link to comment
Share on other sites

No clue what Apache webserver is, so don't think I'll go that option! lol

But I own or manage about 40 domains, some of which are dedicated ips, so I'll just use one of them to do the thumbnails - I hope. Thanks.

Link to comment
Share on other sites

I can certainly understand a little trepidation regarding Apache, but basically it is one of the software programs that allows your web pages to be displayed over the internet. Nonetheless, good luck with your sites and making your thumbs :blink:

Link to comment
Share on other sites

Guest fgumpster

"Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request."

I really need to run this script :) Ideas?

I had troble running this script also. I had to replace the call to "imagejpg()" about line 124 with "imagejpeg()" (with an 'e')

With that little tweak the script was a life saver for me. Thanks jeromas!

Link to comment
Share on other sites

Glad it worked for you :) I'll make the tweak you used in your post. As well, I'm thinking of modding the script to not only make thumbnails, but primary images as well. That way a person won't have to do any sort of mucking about with imagemagick or manually resizing numerous photos. I'll post when it's ready.

Link to comment
Share on other sites

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.   Paste as plain text instead

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