Jump to content

[SOLVED] How Can I Identify Which To Change?


refiking

Recommended Posts

So, I have this code that works as is.  It takes the specified image with the -resampled suffix and adds the word SOLD to it.  There are 2 files for each image.  The original that was uploaded (exm.jpg) and the resized copy (exm.jpg).  Since there are 4 options that can be selected, I want to make a backup of the resampled file.  Ultimately, what I want to do is first check to see if the file exists in the "resampled" directory.  If not, then it should copy the current resampled version (exm-resampled.jpg) into the "resampled" directory (resampled/exm-resampled.jpg).  If it already exists, then, it should make a copy of the image from the resampled version and overwrite the existing file in the images directory.  Then, make the modifications.  Thus keeping the original resmapled version in tact (in the "Resampled" directory).  Here is the code I have so far:

if (isset($_POST['submit_image_sold'])
   && $_POST['submit_image_sold'] == 'Mark as Sold')
    {
// Need Added: Check To see if the image exists in the resampled directory and if not, create it from the image in the images directory
      if ( file_exists ( PATH . '/images/' . $f['id'] . '-resampled.jpg' ) )
       {
     $im = ImageCreateFromJpeg ( PATH . '/images/' . $f['id'] . '-resampled.jpg' );
    $color = imagecolorallocate ( $im, 0xFF, 0xFF, 0xFF );
     $color2 = imagecolorallocate ( $im, 255, 0, 0 );
    imagefilledrectangle ( $im, 3, 3, 57, 24, $color2 );
    ImageTTFText ( $im, '12', 0, 10, 20, $color, PATH . "/fonts/tahoma.ttf", 'SOLD' );
    Imagejpeg ( $im, PATH . '/images/' . $f['id'] . '-resampled.jpg' , 100 );
    ImageDestroy ( $im );
   }

    }

For anyone who might have a similar issue in the future, here is my final code:

if (isset($_POST['submit_image_sold']) && $_POST['submit_image_sold'] == 'Sold'){
    if ( file_exists ( PATH . '/images/' . $f['id'] . '-resampled.jpg' ) ){
		if (!file_exists (PATH . '/images/resampled/' . $f['id'] . '-resampled.jpg')){
		copy(PATH . '/images/' . $f['id'] . '-resampled.jpg', PATH . '/images/resampled/' . $f['id'] . '-resampled.jpg');
		}
	copy(PATH . '/images/resampled/' . $f['id'] . '-resampled.jpg', PATH . '/images/' . $f['id'] . '-resampled.jpg');
	$im = ImageCreateFromJpeg ( PATH . '/images/' . $f['id'] . '-resampled.jpg' );
    $color = imagecolorallocate ( $im, 0xFF, 0xFF, 0xFF );
    	$color2 = imagecolorallocate ( $im, 255, 0, 0 );
    imagefilledrectangle ( $im, 3, 3, 57, 24, $color2 );
    	ImageTTFText ( $im, '12', 0, 10, 20, $color, PATH . "/fonts/tahoma.ttf", 'SOLD' );
    Imagejpeg ( $im, PATH . '/images/' . $f['id'] . '-resampled.jpg' , 100 );
    ImageDestroy ( $im );
   }
    }

Archived

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

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