/** * Replace the image path for the given object ID and ordinal number. * * If no object with that ID and ordinal can be found, creates a new one. * In that case, the $imagetype_key parameter must be non-empty. * @param integer $image_id The object ID * @param integer $ord The ordinal number * @param string $path The path * @param integer $imagetype_key The image type key * @param integer $width The optional width, overrides automatic value * @param integer $ord The optional height, overrides automatic value * @return boolean True on success, false otherwise */ function replace($image_id, $ord, $path, $imagetype_key = '', $width = false, $height = false) { //echo("Image::replace($image_id, $ord, $path, $imagetype_key, $width, $height): Entered<br />"); $objImage = self::getById($image_id, $ord); if (!$objImage && empty($imagetype_key)) { //echo("Image::replace(): Image not found and empty key<br />"); return false; } if (!$objImage) { $objImage = new Image($ord); } File::clean_path($path); $imageSize = getimagesize(ASCMS_DOCUMENT_ROOT . '/' . $path); if ($width === false || $height === false) { $width = $imageSize[0]; $height = $imageSize[1]; //echo("Image::replace(): Image size: $width/$height<br />"); } $path_parts = pathinfo($path); // TODO: Debug stuff, remove in release // $auto_type = $imageSize[2]; // if ($auto_type !== strtoupper($path_parts['extension'])) //echo("Image::replace(image_id $image_id, ord $ord, path $path, imagetype_key $imagetype_key, width $width, height $height): Warning: Image extension (".$path_parts['extension'].") mismatch with type ($auto_type)<br />"); // /TODO if ($imagetype_key) { $objImage->setTypeKey($imagetype_key); } $objImage->setPath($path); $objImage->setFileTypeKey(Filetype::getTypeIdForExtension($path_parts['extension'])); $objImage->setWidth($width); $objImage->setHeight($height); //echo("Image::replace(): Storing Image<br />"); if (!$objImage->store()) { return false; } return $objImage->resize(); }