Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

?? convert all product GIFs into JPGs, and update database.


orlin

Recommended Posts

I have about 2000 products in my clients MS1 shop. Every single one has a GIF image.

 

Now I want to install the PDF catalog report contribution, but it works only with JPGs and PNGs.

 

How can I easily convert all the gifs into jpgs, and also update the database with the new extensions of the images? I'm looking for some effordless automated way....I freak out with the thought that I'll have to open with Photoshop or some other program every single image, save it as jpg, upload it, update database entry....and like that...."only" 2000 times....

 

Any help will be appreciated!!!

 

Orlin.

Link to comment
Share on other sites

i haven't tested this very thouroughly - but this will convert all your images from whatever format into jpegs, put them in the correct folders and then update the database.

 

please backup your database before trying!!!!

 

i have commented out the lines that update the databse and delete the old image. When you are happy that everything is correct from the debug you can uncomment it.

 

Let me know how you get on!

 

<?php

/**

* $Id: remake_thumbs.php,v 1.0 meltus Exp $



* osCommerce, Open Source E-Commerce Solutions

*

* http://www.oscommerce.com

*

* Copyright (c) 2003 osCommerce

*

* Released under the GNU General Public License

*/



require('includes/application_top.php');



require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_PRODUCT_INFO);



?>

<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">

<html <?php echo HTML_PARAMS;

?>>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET;

?>">



<title><?php echo TITLE ?></title>



<base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">



<link rel="stylesheet" type="text/css" href="<?php echo THEMA_STYLE;

?>">

<pre>

<!-- header //-->



<?php require(DIR_WS_INCLUDES . 'header.php');

?>



<!-- header_eof //-->

<?php





       $products_query = tep_db_query("select distinct products_id from products_to_categories");

//echo "select distinct products_id, products_image from products_to_categories";

       while ( $products = tep_db_fetch_array($products_query)) {

               echo  "<br><hr><br>products_id = " . $products['products_id'] . "<br>";

               $products_desc_query = tep_db_query("select products_image from products where products_id = '" . $products['products_id'] . "'");

               while ($products_desc = tep_db_fetch_array($products_desc_query)) {

     echo "<br>image in database = " . $products_desc['products_image'] . "<br>";

                       $image = DIR_FS_CATALOG . DIR_WS_IMAGES . $products_desc['products_image'];

                       if (file_exists($image)) {

     echo "image found - " . $image . "<br>";

    	 $parts = explode(".", $image);



    	 $format = array("", "GIF", "JPG", "PNG");

    	 for ($loop = 0; $loop < count($format); $loop ++) {

       // echo "type = " . strtoupper($parts[count($parts)-1]). "<br>";

       // if (in_array(strtoupper($parts[count($parts)-1]), $format)) {

       if (strtoupper($parts[count($parts)-1]) == $format[$loop]) {

      	 echo "type is - " . $format[$loop] . "<br>";

      	 $the_type = $format[$loop];

       } 

    	 } 

    	 // $format = strtoupper($format[$size[1]]);

    	 if ("JPG" == $the_type)

       $the_type = "JPEG"; 

    	 // use a variable function to create an image from JPG, PNG; GIF, WMBP etc.

    	 $func = "ImageCreateFrom$the_type";

    	 echo "Using - " . $func;

	 

    	 if (function_exists($func)) {

       $createdImageOriginal = $func($image);

    	 }

    	 $image2 = explode(DIR_FS_CATALOG . DIR_WS_IMAGES, $image); 

    	 

    	 $parts = explode(".", $image2[count($image2)-1]);

    	 $image2 = $parts[count($parts)-2] . '.jpg';

    	 echo "<br>image2 = " . $image2 . "<br>";

                           $new_image = DIR_FS_CATALOG . DIR_WS_IMAGES . $image2;

    	 echo "<br>new_image = " . $new_image . "<br>";

    	 imagejpeg($createdImageOriginal, $new_image);

         if ($new_image != $image) {                 

         if (file_exists($new_image)) {       

         echo "<br>update products set products_image = '" . $image2 . "' where products_id = '" . $products['products_id'] . "'";       

         

         // if everything looks right on the debug you can uncomment these two lines to do the database update                                 

        	 //tep_db_query("update products set products_image = '" . $new_image . "' where products_id = '" . $products['products_id'] . "'");

        	 //unlink($image);

                             

                                       }                                

       }

                       }

               }        

 }

?>

</pre>

</body>

</html>

<?php require(DIR_WS_INCLUDES . 'application_bottom.php');?>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...